首页   |   IT资讯   |   综合资讯   |   开发   |   软件   |   问答   |   网络技术   |   网络综合
更多:
当前位置:首页 » 手机数码
文章正文

c#和SQLSERVER2k的一个问题

类型:转载   责任编辑: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

推荐阅读

  • 经历DC“非典时代”:话说问题CCD事件 [详细内容]
  • 库博标准汽车公司选择Infor供应链管理方案 [详细内容]
  • 如何在n-gage上直接查看/编辑txt文件 [详细内容]
  • 智能音乐盛典 水货版多普达585跌至2750元 [详细内容]
  • 顾闻知:给供应链加速 [详细内容]
  • 530允许你对移动开放 [详细内容]
  • 够便宜!奔腾M 1.7GHZ本本仅售5999元 [详细内容]
  • 网友回答:
    网友:knight94

    既然是sql   server,可以如下:  
      string   source=   "data   source=服务器名;initial   catalog=数据库名;user   id=连接用户名;password=密码;";

    .
    站内导航:
    IT热门资讯:
      最佳浏览:1024X768 MSIE
    ©2007 jqmk.com.cn All Rights Reserved