无法从Visual Studio连接到SQL Server 2008 R2 [英] Unable to connect from Visual studio to SQL Server 2008 R2

查看:137
本文介绍了无法从Visual Studio连接到SQL Server 2008 R2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在win 7 32bit中安装了Sql Server 2008 R2.它已正确安装并建立了数据库.我打开了Visual Studio 2010,并编写了一个连接到Sql Server的代码.

I installed Sql Server 2008 R2 in win 7 32bit. It installed correctly and made a database. I opened visual studio 2010 and wrote a code that it connects to Sql server.

cn = new SqlConnection(); 
cn.ConnectionString = Data Source=(local); 
Initial Catalog=XXX_amlak; 
User ID=sa; password=XXX; 
cn.Open();



但出现此错误.



but it has this error.

SQLException was unhandled 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:Named Pipes Provider,error:40-could not open a connection to SQL Server)



Visual Studio自动安装了SQL Express.我禁用了Internet安全性.



Visual Studio has installed SQL Express automatically.I disable my Internet security.

推荐答案

您遇到以下两种情况之一:
1)您的连接字符串是kaput,需要固定(这是我的假设,因为(local)"不太可能是有效的实例名称.此值需要反映使用Management Studio登录时使用的正确实例名称) .通常类似于"localhost/INSTANCE"或"MACHINENAME/INSTANCE".
2)您的SQL Server不接受远程连接.
You have either one of two situations:
1) Your connection string is kaput and needs to be fixed (This is my assumption, as "(local)" is not likely a valid instance name. This value needs to reflect the proper instance name that you use when you logon using Management Studio. Usually something like ''localhost/INSTANCE'', or ''MACHINENAME/INSTANCE''.
2) Your SQL server is not accepting remote connections.


这篇关于无法从Visual Studio连接到SQL Server 2008 R2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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