i want to connect SQL server in C# application plz help how can i Connect DB in C#???

1-import the nameSpace

using System.Data.SqlClient

2- Make a new object from SqlConnection Class

SqlConnection conn = new SqlConnection();

3- set the ConnectionString property of the SqlConnection;

string connString = @"Data Source=ServerName;Initial Catalog=DataBaseName;Integrated Security=True";

set Integrated Security=True if you will use Windows Authntication
you will find a good tips about the ConnectionString on this Site
http://www.connectionstrings.com/
Then open the Connection

conn.Open()

and after you finish your work with the DB close the Connection

conn.Close()

Or you Can Use the Connection Wizard of VS as follows:
from Data Menu Choose Add new Data Source
then choose DataBase , Click newConnection , choose Server Name,
if the any userName or Password for DB set it , Choose DB Name , press Ok.

i want to connect SQL server in C# application plz help how can i Connect DB in C#???

Hi
Try this

Using System.Data.Sqlclient; is the namespace to connect db

sqlconnection con=new sqlconnection("Data Source=localhost;Initial Catalog=Northwind;User ID=sa");

Thanks,
Paul daniel

This article has been dead for over six months. Start a new discussion instead.