解决vs2005无法连接sql数据库问题
<初学者>
今天用vs.net2005连接sql2000时出现了错误。。
在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会
导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连
接)
我知道我的vs里自来个sql2005express版本。我要连接sql2000不是2005啊。。
怎么才能连接到2000呢。要打sp4补丁吗?郁闷中。。。代码如下:
using System;
using System.Data;
using System.Data.SqlClient;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
class Sample
{
public static void Main()
{
SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
SqlCommand catCMD = nwindConn.CreateCommand();
catCMD.CommandText = "SELECT CategoryID, CategoryName FROM Categories";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
nwindConn.Open();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
SqlDataReader myReader = catCMD.ExecuteReader();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
while (myReader.Read())
{
Console.WriteLine("\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
myReader.Close();
nwindConn.Close();
}
}
今天用vs.net2005连接sql2000时出现了错误。。
在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会
导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连
接)
我知道我的vs里自来个sql2005express版本。我要连接sql2000不是2005啊。。
怎么才能连接到2000呢。要打sp4补丁吗?郁闷中。。。代码如下:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
代码很简单。。可就是连接不上。。
PS:问题解决了,原来是实例的问题,哈哈。。
连接字符串server后面加上.\\sql2000的实例名
就OK了。。
在这里感谢晓月无铭