Click here to Skip to main content
16,022,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends

Please tell me how to connect with sql server with c# when we are in Window Authentiation mode in sql server. while connecting with SQL i am writing following code...
C#
SqlConnection con = new SqlConnection();
                con.ConnectionString = " Data Source = UPADHYAY-PC\\SQLEXPRESS; Initial Catalog = belwal";
                con.Open();

but its showing Logon fail. because there is not user id and password. ...

please help....

thanks
Posted
Updated 3-Oct-12 1:22am
v2

in case of window authentication mode......
use following code

SqlConnection con = new SqlConnection();
con.ConnectionString = " Data Source = UPADHYAY-PC\\SQLEXPRESS; Initial Catalog = belwal; integrated Security=true;"
 
Share this answer
 
For window authentication mode
C#
con.ConnectionString = " Data Source = localhost\\SQLEXPRESS; Initial Catalog = belwal; integrated Security=true;"
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900