数据库的连接方法有21、在web.config 文件添加
<appseting><add key="ConnectionString"value=."uid=sa;password=123;database=;server=;"> //其中的sa和123分别为数据库设置的账户和密码</appseting>调用时:string connectionString= System.Configuration.ConfigurationManager.AppSetings["ConnectionString"].ToString();2、在web.config 文件添加
<connectionStrings> <add name="registerconnectionstring" connectionString="Data Source=.;UID=sa;PWD=123;DATABASE=register" providerName="System.Data.SqlClient"/> </connectionStrings>
调用时:
string strConn = WebConfigurationManager.ConnectionStrings["registerConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(strConn);