[英]How to get SQL Server Name Using Windows Authetication in C#
I am trying to fetch the Server Name using C# for that I am trying blow mentioned code. 我正在尝试使用C#来获取服务器名,因为我正在尝试提及代码。
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#. 这给了我一个异常,例如用户Dhaval.patel的登录失败,因此任何人都可以帮助使用C#中的window Authetication进行连接。
尝试这样使Integrated Security = true
con = new SqlConnection("Data Source=.;Database=Master; Integrated Security=true");
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, eg, 如果您有SQL Server的命名实例,则还需要添加它,例如,
"Server=localhost\sqlexpress"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.