在web.config中写入:
<connectionStrings> <add name="ConnectionString" connectionString="Data Source=61.139.105.141;Initial Catalog=libdb;User ID=sa;password=jsb" providerName="System.Data.SqlClient"/> </connectionStrings >
调用:
Dim conn As SqlConnection = New SqlConnection Dim cmd As SqlCommand = New SqlCommand conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ToString cmd.Connection = conn
当然,建议封装一个数据库访问类.
注意:使用System.Configuration.ConfigurationManager需要增加引用:
System.Configuration