<appSettings>
<add key="ConnStr" value="server=192.168.1.1;database=eforum;uid=sa;pwd=;"></add>
 </appSettings>

解决方案 »

  1.   

    在web.config 中加入:
    <sessionState 
                sqlConnectionString="data source=localhost;
                   Integrated Security=SSPI;
                   Initial Catalog=northwind"
                cookieless="false" 
                timeout="10"/>
      

  2.   

    用楼上的方法设置.然后使用 ConfigruationSettings.AppSettings["ConnStr"] 取得字符串
      

  3.   


    在asp.net应用程序下找到web.config文件,在<system.web>前面加入下面的代码:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>    <appSettings>
            <add key="ConnectionString" value="server=jeff;uid=sa;pwd=btk;database=msg" />
        </appSettings> 
       
      <system.web>
     ......
      </system.web>
    </configuration>   
     
      

  4.   

    <appSettings>
    <add key="ConnStr" value="server=(local);database=eforum;uid=你的登陆名;pwd=你的密码;"></add>
     </appSettings>在程序中使用ConfigurationSettings.AppSettings("sqlserver")来得到value的值!
    例如dim connstr as string=ConfigurationSettings.AppSettings("sqlserver")
      

  5.   

    写错了,不好意思,应该是ConfigruationSettings.AppSettings["ConnStr"]string connstr =ConfigurationSettings.AppSettings("sqlserver")
      

  6.   

    1.web.config
    <configuration>
    <appSettings>
       <add key="sqlserver" value="Password='你的SQL登录密码';Persist Security Info=True;User ID='你的SQL登录名';Initial Catalog='eForum';Data Source='(LOCAL)'" />
    </appSettings>
    </configuration>2.在程序中引用:
    string myConnectString = ConfigurationSettings.AppSettings["sqlserver"];
        SqlConnection myConnection = new SqlConnection(myConnectString);
        myConnection.Open();
      

  7.   

    哈哈!
    木林森 C#和ASP.NET程序设计教程 清华大学出版社
    中介绍的应该就是你说得这样论坛吧
      

  8.   

    我想知道, VB.NET的WEBFORM怎么实现与数据库连接,好象和WINDOWS应用程序不一样啊!
    我们老师都搞不懂,期待中!谢谢
      

  9.   

    设置按照前面兄弟写的就行了.用以下方法使用:
    1:using System.Configuration;
    2:this.sqlConnection1.ConnectionString =ConfigurationSettings.AppSettings["这里是你在web.config文件中的key的值"];
      

  10.   

    我已经改了,可使仍然出现错误啊;如下:Server Error in '/lwei' Application.
    --------------------------------------------------------------------------------SQL Server does not exist or access denied. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.Source Error: 
    Line 50:      cn=new SqlConnection(strConn);
    Line 51:      // 打开连接
    Line 52:      cn.Open();
    Line 53:      // 构造SQL语句,该语句往RegUsers表中添加一条记录
    Line 54:      String strSQL="insert into RegUsers (NickName,Password,Sex,Birthday,"+
     Source File: F:\lwei\Untitled-1.aspx    Line: 52 Stack Trace: 
    [SqlException: SQL Server does not exist or access denied.]
       System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) +474
       System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) +372
       System.Data.SqlClient.SqlConnection.Open() +384
       ASP.Untitled_1_aspx.RegBtn_Click(Object sender, EventArgs e) in F:\lwei\Untitled-1.aspx:52
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain() +1277   。其中的下面一段代码是什么意思啊?
    Server Error in '/lwei' Application.
    --------------------------------------------------------------------------------SQL Server does not exist or access denied. 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.      请指教!
      

  11.   

    <appSettings>
     <add key="DBConnStr" value="server=QIN;uid=sa;pwd=123;database=WorkGuide_new"/>
    </appSettings>C#:
    public SqlConnection getConnection()
    {
    string connStr = ConfigurationSettings.AppSettings["DBConnStr"];
    SqlConnection con=new SqlConnection(@connStr);
    return con;
    }
      

  12.   

    <appSettings>
     <add key="DBConnStr" value="server=QIN;uid=sa;pwd=123;database=WorkGuide_new"/>
    </appSettings>C#:
    public SqlConnection getConnection()
    {
    string connStr = ConfigurationSettings.AppSettings["DBConnStr"];
    SqlConnection con=new SqlConnection(@connStr);
    return con;
    }