Reputation: 7591
I am trying to fetch the Server Name using C# for that I am trying blow mentioned code.
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;
con = new SqlConnection("Data Source=.;Database=Master;Integrated Security=SSPI");
con.Open();
cmd = new SqlCommand("select * from sysservers where srvproduct='SQL Server'", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
ServerCollection.Add(dr[2].ToString());
}
dr.Close();
it's give me Exception like Login faild for user Dhaval.patel so can anyone please help how to connect using window's Authetication in C#.
Upvotes: 0
Views: 101
Reputation: 11721
It should be like :-
("Server= localhost; Database=Master;Integrated Security=SSPI, Integrated Security=True");
If you have a named instance of SQL Server, you'll need to add that as well, e.g.,
"Server=localhost\sqlexpress"
Upvotes: 0
Reputation: 4963
Try to Put Integrated Security = true
like this
con = new SqlConnection("Data Source=.;Database=Master; Integrated Security=true");
Upvotes: 1