string str="Data Source=localhost;User ID=sa;Password=aa2;Initial Catalog=test;Initial Catalog是你要访问的那个表名

解决方案 »

  1.   

    用的不是localhost,另外,你这个和我的有区别吗?
    还有,可以不指定database,直接指定表吗?
      

  2.   

    不是localhost的话这个改一下就可以了
    try it 睡觉去了~^_^
      

  3.   

    string str="Data Source=localhost;User ID=sa;Password=aa2;Initial Catalog=test;"test一定是数据库名
      

  4.   

    见鬼了,同一句connect string,在控制台里就是好的,在web上就有问题。
      

  5.   

    string  str=  "server=aa-one;uid=sa;pwd=aa2;database=Northwind";字符串里面缺少一个分号,应该为string  str=  "server=aa-one;uid=sa;pwd=aa2;database=Northwind;";就对了,你再试试。
      

  6.   

    我的问题非常的奇怪,同一条connect string,我放到console application里,就能连上,放到Web application中,就是连不上。
    太有郁闷了。
      

  7.   

    你的catch  (exception e)
    {
    Console.write (e.ToString());}
    看看具体的问题!
      

  8.   

    System.Data.SqlClient.SqlException: SQL Server 不存在或访问被拒绝。 at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) at System.Data.SqlClient.SqlConnection.Open() at SmsMIS.Web.WebForm2.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\smsmis\webform2.aspx.cs:line 34 
    -------------
    注:这次我用的是sqladapter的向导生成的connect string
      

  9.   

    server=aa-one;uid=sa;pwd=aa2;database=Northwind
    连接串完全正确,是最简单的连接串写法.
    我一向也这样写的至于为什么在 web application 上出现这个问题. 就真的很奇怪了.
    catch(SqlException ex) 看看 ex 是什么?
      

  10.   

    我也遇到相关问题
    借楼主的地方问一下: 
      xp下安装sql server个人版,可以远程连接么?
      

  11.   

    我用vs的SqlAdapter生成向导生成的Sqlconnecttion连接居然也不行。唉,我的第一份工作、第一天上班呀,居然遇到这样ft的事。
      

  12.   

    ghostmirror(BUPT):
     反正iis在xp下限制5个连接,sql就不知道了。
      

  13.   

    SQL服务器->右键->属性配置->安全性->身份验证:选WINDOWS和SQL SERVER
      

  14.   

    回复人: lijun84(李俊俊) ( ) 信誉:100  2004-03-22 23:58:00  得分:0 
     
     
      SQL服务器->右键->属性配置->安全性->身份验证:选WINDOWS和SQL SERVER  
     
    ----------------------
    不可能是这个问题,不然用vs.net是连不上的,用console也不会连上。
      

  15.   

    Gorgee(.Net马夫)
    string str="Data Source=localhost;User ID=sa;Password=aa2;Initial Catalog=test;"test一定是数据库名哈哈不好意思搞错了
    test是数据库名^_^
      

  16.   

    我也碰到了,
    上次SQL server 服务器升级,然后我的web就连不上了。
    后来我们的DBA不只怎么设置了一下,就好了。
    所以是SQL server的问题我的贴子:
    http://expert.csdn.net/Expert/topic/2869/2869525.xml?temp=.1514093
    个人认为问题还没解决。
      

  17.   

    up,upup,upupup
    紧紧跟紧,关注无限!!!
      

  18.   

    <%@ Import namespace = "System.Data"%>
    <%@ Import namespace = "System.Data.SqlClient"%>
    <%@ Page Language="C#" Debug="true" %>
    <html>
    <head>
    <title>DataReader</title>
    </head>
    <body>
    <h1>DataReader</h1>
    Total Products listed = 
    <asp:DataGrid id ="dgCount" runat = "server"
    BorderWidth = "0" ShowHeader="False"/>
    <br/>
    <asp:DataGrid id = "dgData" runat = "server"/>
    </body>
    </html><script language = "c#" runat = "server">
    private void Page_Load(object sender, System.EventArgs e)
    {
    String strConnection = "server = local;database = Northwind;integrated security = true";
    SqlConnection objConnection = new SqlConnection(strConnection);
    objConnection.Open();
    String strSQLcount;
    strSQLcount = "SELECT COUNT(ProductName)FROM[Product Sales for 1997]";
    SqlCommand objCommand = new SqlCommand(strSQLcount,objConnection);
    SqlDataReader objReader = objCommand.ExecuteReader(); dgCount.DataSource = objReader;
    dgCount.DataBind();
    objReader.Close();

    String strProcName;
    strProcName = "SELECT * FROM [Product Sales for 1997]";
    objCommand.CommandText = strProcName;
    objReader = objCommand.ExecuteReader(); dgData.DataSource = objReader;
    dgData.DataBind();
    objConnection.Close();
    }
    </script>
    我这也是连不上sql server,????
      

  19.   

    <%@import Namespace="System.Data"%>
    <%@import Namespace="System.SqlClient"%>
    <script runat="server" language="c#">
    void Page_Load()
    {
    string con="server=172.18.192.33;uid=sa;pwd=;database=xxkweb;";
    SqlClientConnection objConnection=new SqlClientConnection(con);
    SqlClientCommand objCommand1 = new SqlClientCommand("select * from users",objConnection);
    objConnection.Open();
    dgrdMain.DataSource=objCommand1.ExecuteReader();//dgrdMain就是下面的DATAGRID的ID
    dgrdMain.DataBind();
    objConnection.Close();
    }
    </script>
    <html>
    <body> 
    <asp:DataGrid id="dgrdMain" cellpadding="1" showheader="true" borderwidth="0" runat="server" /> 
    </body>
    </html> 
    我的也是,连出错信息都没有,只有什么叫我把errormessage的mode设为off的页面,连教程里的.aspx都不能运行,出错界面一样。帮我一下瓦