解决vs2005无法连接sql数据库问题

<初学者>
今天用vs.net2005连接sql2000时出现了错误。。
在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会
导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连
接)
我知道我的vs里自来个sql2005express版本。我要连接sql2000不是2005啊。。
怎么才能连接到2000呢。要打sp4补丁吗?郁闷中。。。代码如下:
None.gif using  System;
None.gif
using  System.Data;
None.gif
using  System.Data.SqlClient;
None.gif
None.gif
class  Sample
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif  
public static void Main() 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif    SqlConnection nwindConn 
= new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
InBlock.gif
InBlock.gif    SqlCommand catCMD 
= nwindConn.CreateCommand();
InBlock.gif    catCMD.CommandText 
= "SELECT CategoryID, CategoryName FROM Categories";
InBlock.gif
InBlock.gif    nwindConn.Open();
InBlock.gif
InBlock.gif    SqlDataReader myReader 
= catCMD.ExecuteReader();
InBlock.gif
InBlock.gif    
while (myReader.Read())
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif      Console.WriteLine(
"\t{0}\t{1}", myReader.GetInt32(0), myReader.GetString(1));
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    myReader.Close();
InBlock.gif    nwindConn.Close();
ExpandedSubBlockEnd.gif  }

ExpandedBlockEnd.gif}

代码很简单。。可就是连接不上。。

PS:问题解决了,原来是实例的问题,哈哈。。

连接字符串server后面加上.\\sql2000的实例名
就OK了。。
在这里感谢晓月无铭

转载于:https://www.cnblogs.com/chenboneu/archive/2007/03/06/666088.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值