类型:转载 责任编辑:asp 日期:2007/03/01
我按照《c#编程》这本书上的提供的代码写了如下的程序:
using system;
using system.data.oledb;
public class datareader
{
public static void main(string[] args)
{
string source="provider=sqloledb;"+"server=\\xd-wth;"+"uid=administrator;pwd=wcjjws;"+"database=northwind";
string select="select contactname,companyname from customers";
oledbconnection conn=new oledbconnection(source);
conn.open();
oledbcommand cmd=new oledbcommand(select,conn);
oledbdatareader areader=cmd.executereader();
while(areader.read())
console.writeline("{0} from {1}",areader.getstring(0),areader.getstring(1));
areader.close();
conn.close();
}
}
编译使用下面的命令:
csc /t:exe /r:system.data.dll sql.cs然后运行这个程序,出现下面的出错提示:
c:\inetpub\wwwroot\csharp>sql.exe
未处理的异常: system.data.oledb.oledbexception: [dbnetlib][connectionopen (connect()).]sql server 不存在或拒绝访问。
at system.data.oledb.oledbconnection.processresults(int32 hr)
at system.data.oledb.oledbconnection.initializeprovider()
at system.data.oledb.oledbconnection.open()
at datareader.main(string[] args)
我安装的是sqlserver2k,我把鼠标移动到工具栏上的sql服务器图标时出现\\xd-wth的提示,我曾经使用uid=qsuser;pwd=qspassword
这到底是什么原因望解释
在就是,编译的时候为什么使用csc /t:exe /r:system.data.dll sql.exe,不能直接是csc sql.cs
推荐阅读
既然是sql server,可以如下:
string source= "data source=服务器名;initial catalog=数据库名;user id=连接用户名;password=密码;";