简体   繁体   English

Microsoft SQL Server 2005的连接字符串中存在问题!

[英]Problem in the connection string of Microsoft SQL Server 2005 !

I have MSSQLServer 2005 installed on my machine. 我的机器上安装了MSSQLServer 2005。 I am creating a connection string like this: 我正在创建这样的连接字符串:

String sqlConnectionString= user id=admin; 字符串sqlConnectionString =用户ID = admin; password=admin; 密码=管理员; server=MachineName\\MSSQLSERVER; 服务器=计算机名\\ MSSQLSERVER; Trusted_Connection=no; Trusted_Connection =无; database=MYDataBase; 数据库= MYDATABASE; connection timeout=30 连接超时= 30

When I do: myConnection = new SqlConnection(sqlConnectionString); 当我这样做时:myConnection = new SqlConnection(sqlConnectionString);
myConnection.Open(); myConnection.Open();

Open() command throws an exception : Open()命令引发异常:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. 建立与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. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: SQL Network Interfaces, error: 25 (提供者:SQL网络接口,错误:25

Also the same string works fine on SQLEXPRESS/ 同样的字符串在SQLEXPRESS /上也可以正常工作

****I have configured Sql Express to accept remote connections by choosing "Local and remote connection".Also I started SQL Browswer service.**** ****我已通过选择“本地和远程连接”将Sql Express配置为接受远程连接。此外,我还启动了SQL Browswer服务。

Is there anything wrong in connection string? 连接字符串有什么问题吗?

You must have made a typo somewhere. 您一定在某处打错了字。 Try this: 尝试这个:

  1. Load up Visual Studio. 加载Visual Studio。
  2. Go to the "Server Explorer" tool window. 转到“服务器资源管理器”工具窗口。
  3. Create a new data connection. 创建一个新的数据连接。
  4. Fill in your required values, click the "Test Connection" button to make sure they work, then click OK. 填写所需的值,单击“测试连接”按钮以确保它们起作用,然后单击“确定”。
  5. Click on your new connection in the "Server Explorer", and you can copy and paste the connection string from the Properties tool window. 在“服务器资源管理器”中单击新连接,然后可以从“属性”工具窗口复制并粘贴连接字符串。

Have a look at http://www.connectionstrings.com/sql-server-2005 看看http://www.connectionstrings.com/sql-server-2005

And verify that your names are correct. 并确认您的名字正确。

Make sure that you have 'SQL server and Windows Authentication mode' set under 'Server authentication' in 'Security' properties. 确保在“安全性”属性的“服务器身份验证”下设置了“ SQL服务器和Windows身份验证模式”。 Your connection string implies that you are using SQL authentication. 您的连接字符串表示您正在使用SQL身份验证。 If you have 'Windows Authentication mode' set you may receive this error. 如果您设置了“ Windows身份验证模式”,则可能会收到此错误。

Try setting the server name to just the name of your machine, as in 'server=MachineName;'. 尝试将服务器名称设置为仅计算机名称,如“ server = MachineName;”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM