Category: ASP . 2009-07-08 19:40 183 people read reviews (0) favorite reports
Method One,
1. Add the following connection code to <configuration> under Web. config
<connectionStrings>
<add name= "Test" connectionstring= "server=.; uid=sa;pwd=;D atabase=tcedu; Connect timeout=90 "providername=" System.Data.SqlClient "/>
</connectionStrings>
2. Add the following code in the background code, where test is the name of the data connection in Web. config (name)
SqlConnection con = new SqlConnection (configurationmanager.connectionstrings["Test"]. ConnectionString);
Method Two,
1. Add the following connection code to <configuration> under Web. config
<appSettings>
<add key= "Test" value= "Data source=.;i Nitial catalog=tcedu; User id=sa;password= "/>
</appSettings>
2. Add the following code in the background code, where test is the name of the data connection in Web. config (name)
SqlConnection con = new SqlConnection (configurationmanager.appsettings["Test"]);
C # New way to connect to a database (via the Web. config configuration file)