.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Creating SQL Connection

Posted By:Nikhil Kumar       Posted Date: February 20, 2010    Points: 10    Category: ADO.NET    URL: http://www.dotnetspark.com  

Showing how to create a sql connection by code...(Basic). Type this code to create a sql connection using ADO.Net
 



Type this code to create a sql connection :

//con is the object of SqlConnectoin_ 

SqlConnectoin con= new SqlConnetoin(); 
con.ConnectionString = "Data Source =Sqlservername ; Initial Catalog = table name; Integrated Security = True"; 
con.Open(); 
//Here Sqlserver name = your computer name

(You can see your computer name by : 
right click on MyComputer --> Properties -->Computer Name (tab) --> Change (BUtton) 

//If you are connecting sql with user id and 

password than remove Integrated security and type : 
SqlConnectoin con= new SqlConnetoin(); 
con.ConnectionString = "Data Source =Sqlservername ; Initial Catalog = table name; User id = youruserid; password = yourpassrd"; 
con.Open();

Thanks !!

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend