连接数据库用什么方法?(我指的是当打开网页时会连接到数据库,这个数据库的位置是动态的,数据库的信息应该用什么方法保存一个配置文件?我试了一下XML好象不能用,我用的是vb.net写asp.net程序)谢谢另外大家能推荐几本ASP.NET的书吗?

解决方案 »

  1.   

    可以保存在web.config中啊。
    修改时,可以用asp.net 操作 xml的方法来修改web.config的值。楼主看一下system.xml吧
      

  2.   

    //asp.net 操作 xml的方法来修改web.config的值能给点提示吗?
      

  3.   

    把数据库连接保存到web.config内
    用的是时候读取就可以了
      

  4.   

    我想知道 怎么能用XML来读取或编辑web.config内容
    谢谢!
      

  5.   

    web.config
    ----------
    <configuration>
    ......
    <appSettings>
    <!--
    设置数据库连接字符串配置
    -->
    <add key = "ConnectionString" value= "server=localhost;database=hotop100;User ID=sa;password=sa;"/>
    </appSettings>
    ............
    </configuration>
    -----------
    .cs
    System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
      

  6.   

    我想知道 怎么能用XML来读取或编辑web.config内容
    ---------------------
    可以读取,但不能修改吧
      

  7.   

    我想知道 怎么能用XML来读取或编辑web.config内容
    ---------------------
    可以读取,但不能修改吧可以更改的,但是,如果更改了,那么Session将会丢失!http://community.csdn.net/Expert/topic/4708/4708648.xml?temp=.377331
      

  8.   

    一般是放在web.config文件中
    <appSettings>
    <add key="strConn" value="workstation id=All;packet size=4096;UID=sa;password=;data source=(local);persist security info=True;initial catalog=TestOnline;Max Pool Size=500;Min Pool Size=5"/>

     </appSettings> 
    也有的在程序中,用static变量存储数据库信息。明白?
      

  9.   

    <appSettings>
    <!--
    设置数据库连接字符串配置
    -->
    <add key = "ConnectionString" value= "server=localhost;database=hotop100;User ID=sa;password=sa;"/>
    </appSettings>
    ............
    </configuration>
    -----------
    .cs
    System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
      

  10.   

    //*数据库的位置是动态的*//这是什么意思?
    难道你还动态的生成新的数据库?
    要是固定的多个数据库无非就在web.config里多add 几个key就是了。
    然后根据不同情况读取不同的配置
      

  11.   

    truecoffeefox(咖啡狐)
    我的意思是管理员可以指定数据库的位置,这样数据库的位置就不是固定的了。
    所以我需要在管理员修改数据库位置后能连接上,就导致了这个问题的产生。
      

  12.   

    我在web.config文件里添加了下面的内容
    <configuration>    
    <appSettings>
               <!--数据库位置-->
       <DataS>C:\11.mdb</DataS>
      <!--数据库密码-->
       <DataP>123456</DataP> 
    </appSettings>
     <system.web>
    ……
    </system.web>
    </configuration>然后在一个BUTTON的CLICK事件里添加下面代码        Dim XmlDoc As New System.Xml.XmlDocument()
            Dim XmlRead As System.Xml.XmlNode = XmlDoc.DocumentElement
            Dim XmlSelect As System.Xml.XmlNode
            XmlDoc.Load(Server.MapPath("web.config"))
            XmlSelect = XmlRead.SelectSingleNode("/configuration/appSettings/DataS")
            TextBox1.Text = XmlSelect.InnerText.ToString但是结果却是报错。Object reference not set to an instance of an object. 
    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.NullReferenceException: Object reference not set to an instance of an object.Source Error: 
    Line 35:         Dim XmlSelect As System.Xml.XmlNode
    Line 36:         XmlDoc.Load(Server.MapPath("web.config"))
    Line 37:         XmlSelect = XmlRead.SelectSingleNode("/configuration/appSettings/DataS")‘这行出错!!!!
    Line 38:         TextBox1.Text = XmlSelect.InnerText.ToString 
    Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.]
       wdw.WebForm1.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\wdw\index.aspx.vb:37
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102 什么原因啊?
    谢谢
      

  13.   

    真是不爽啊,告诉你system.xml可以读可以改web.config才给俺2分.