SQL2000与SQL2005连接字符串设置.
学习笔记:
VS通常将数据库的连接字符串设置在Webconfig中添加连接字符串键设置如下:
SQL2000
webconfig添加键:
<configuration>
<appsettings>
<add key="SQLConnection" value="data source.;database=DB;user id=sa;password= "/>
</appsettings>
</configuration>
程序调用:string connectionstring=ConfigurationSetting.Appsettings["SQLConnecton"]
SQL2005
webconfig设置:
<configuration xmlns=http://schemas.microsoft.com/.NetConfiguration/v2.0>
<connectionStrings>
<add name="NorthwindConnectionString"connectionString="DataSource=.;Initial Catalog=Northwind;User ID=sa;Password= "providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
程序调用:string conn = WebconfigurationManager.ConnectionStrings["NorthwindconnectionString"].connectionString;
ASP.NET 2.0连接字符串的设置是通过WebConfigurationMannager来管理的,它属于System.WebConfiguration(修正:System.Web.Configuration)命名空间.