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

Recommended Answers

All 6 Replies

>how can i Connect DB in C#???
Learn the basics of ADO.NET provider classes.

Member Avatar for m.a.u.

Ever heard about LINQ?

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

Go through msdn, and study the basic......

commented: Good suggeston. +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.