asp.net2.0连接配置
小弟学浅刚学asp.net2.0,原来学的是1.1连接SQL2000时在web.congfig里配置的连接串
<appSettings>
<add key= "DSN " value= "server=.;uid=sa;pwd=ok;database=OASystem "> </add>
</appSettings>
然后这样读取
string strCon = System.Configuration.ConfigurationSettings.AppSettings[ "DSN "];
现在用vs.net2005还用这种方法的话,虽然没有错,但是会有警告
System.Configuration.ConfigurationSettings.AppSettings
“已经过时”,啊哈,过时了,确实如此,不知道asp.net2.0里面该如何配置连接数据库和读取,谢谢各位达人了
------解决方案--------------------帮顶
------解决方案--------------------可以用的,
但是推荐的用法是:
<connectionString>
<add key= "DSN " value= "server=.;uid=sa;pwd=ok;database=OASystem; " />
</connectionString>
using System.Configuration;
ConfigurationManager cm = new ConfigurationManager();
string connStr = cm.ConfigurationSettings.ConnectionString[ "DSN "];
大概是这个样子,好久没有再用了,忘了,
楼主可以上msdn上查一下
有例子的
------解决方案--------------------using System.Configuration;
ConfigurationManager.AppSettings[DSN].ToString()
------解决方案--------------------写在web.config中
<connectionStrings>
<add name= "UURedUnionConnectionString " connectionString= "Data Source=ANDY;Initial Catalog=UURedUnion;User ID=sa;Password=huangliang " providerName= "System.Data.SqlClient "/>
</connectionStrings>
在程序中调用
public static readonly string CONN_STRING = System.Configuration.ConfigurationManager.ConnectionStrings[ "UURedUnionConnectionString "].ConnectionString;
------解决方案--------------------呵呵,其实原理还是一样的。楼主可以看看这个 http://data.socut.com ,有详细的经验总结。
------解决方案-------------------- <connectionStrings>
<add name= "conn " connectionString= "Data Source=127.0.0.1;Initial Catalog=数据库名字;Persist Security Info=True;User ID=账号;Password=密码 " providerName= "System.Data.SqlClient "/>
</connectionStrings>
VB语法
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings( "conn ").ConnectionString.ToString)
conn.open()
conn.close()
1.1跟2.0的有区别了,调用的参数是ConfigurationManager.ConnectionStrings