使用Windows身份验证连接到SQL Server [英] Connecting to SQL Server using windows authentication

查看:261
本文介绍了使用Windows身份验证连接到SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用以下代码连接到SQL Server时:

When I was trying to connect to SQL Server using the following code:

SqlConnection con = new SqlConnection("Server=localhost,Authentication=Windows Authentication, Database=employeedetails");
con.Open();
SqlCommand cmd;
string s = "delete employee where empid=103";

我收到以下错误:

建立与SQL Server的连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称正确,并且已将SQL Server配置为允许远程连接. (提供者:SQL网络接口,错误:25-连接字符串无效)

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)

推荐答案

SQL Server的连接字符串应类似于:"Server= localhost; Database= employeedetails; Integrated Security=True;"

A connection string for SQL Server should look more like: "Server= localhost; Database= employeedetails; Integrated Security=True;"

如果您有SQL Server的命名实例,则还需要添加它,例如"Server=localhost\sqlexpress"

If you have a named instance of SQL Server, you'll need to add that as well, e.g., "Server=localhost\sqlexpress"

这篇关于使用Windows身份验证连接到SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆