So far we have written applications to talk to various Databases. This is the first time, wrote a C# .Net console application to fetch records from DB2. Following is the sample code.
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Odbc;
classProgram
{
staticvoid Main()
{
OdbcCommand cmd = null;
OdbcConnection con = null;
OdbcDataReader rdr = null;
try
{
con = newOdbcConnection("DSN={LibName};UID={User Name};PWD={Password};" + "Driver={IBM DB2 ODBC DRIVER};");
Following is the SQL query used to delete all records from all tables from Database.
This is useful during development scenarios where you need to get rid of all the dummy records and insert a fresh data.
SQL Query: Appropriate comments are provided to explain its operation
/* The Following set of queries is used to delete all records from all tables from your database */
I was writing a user manual for a client, A part of it is about setting up a database in SQL Server 2008 from .MDF file. Thought let me blog this simultaneously so that it could be useful for surfer who look for a way to setup a database in SQL Server.Necessary measures are taken to protect sensitive information :)
Following are the steps to be done to setup database in SQL Server 2008.
Step #1: Right click on Database, Select Attach…
Step #2: A window with title Attach Databases will be shown to add the database files. Click on Add button.
Step #3: A window with title Local Database files – Computer Name, will be displayed. Browse and select the respective .mdf file for which you need to add the Database.
(Click to view full screen)
Step #4: The select database file with the .mdf life & the .ldf file will be loaded. Please refer Screen #48. There are two options either we can click OK to finish adding the Database or If you want to reset log file .ldf file, select and remove the second file as shown in screen #48 and click OK to add file Database with log file. When this activity is done the SQL Server automatically creates a .ldf file.
I use SQL Server 2005 in my development server and the Database files (.MDF & .LDF) were in C drive. As we were working on the development the LDF (Transaction log files) increased drastically. So i thought its times to reduce it or later it might make the system slow or space crunch would be there.
The tried following options to reduce the LDF file:
1. Right click on Database -> Tasks -> Shrink -> Files -> Choose File type : Log > Selected Shrink action : Release unused space & later Reorganize pages, Both did not help as the log was more than 1 GB whihc is not so much because i have seen some people had it more 40 GB when log file was not monitored frequently.
2. Used DBCC shrinkfile some time before, which was also not helpful.
Then found from the forums & did the following which worked:
Steps: 1. Make the database offline. 2. Right click & did 'Detach...' for the respective database. 3. Went to the file system where the LDF file resides and moved to a safer place. 4. Then on databases folder (below the Server icon), did right click & clicked Attach. 5. In Attach database window, selected the database & attached it without LDF file. So that system automatically created a new one which is of very small size :)
Thus the issue was solved. I believe there are other options as well to reduce LDF files, If you are aware of any other options feel free to write it down :)