关于web.config文件和class.cs的写法 [英] about web.config file ,and class.cs how to write tell something
本文介绍了关于web.config文件和class.cs的写法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在web.config文件的一个连接中连接所有连接字符串
解决方案
在web.config的侧面连接字符串中文件
< connectionStrings> < add name = " connectionString = " 数据源= 192.168.1.4;数据库= BaryNew;用户ID = sa;密码= baryons1"/> < add name = " connectionString = " 数据源= 192.168.1.4;数据库= Bary;用户ID = sa;密码= baryons1"/> < add name = " connectionString = " 数据源= WIN-3U37PS1RHVF;初始目录= Bary123;集成安全性= True" providerName = System.Data.SqlClient"/> </ connectionStrings >
< connectionstrings> < add connectionstring = " name = 连接"/> < add connectionstring = " name = Connection1"/> < add connectionstring = " name = Connection2"/> </ 连接字符串 >
您可以从代码中访问
字符串 = Convert.ToString(ConfigurationManager.ConnectionStrings [ 0 ]) ;OR
字符串 = Convert.ToString(ConfigurationManager.ConnectionStrings [ 1 ]) ;OR
字符串 = Convert.ToString(ConfigurationManager.ConnectionStrings [ 2 ]) ;
尝试这些链接
^ ]
http://www.connectionstrings.com/Articles/Show/store-connection-string-in-web-config [ ^ ]
how to connect a all connection string in one connection in web.config file
解决方案
in side connection string in web.config file
<connectionStrings> <add name="ConnectionString" connectionString="Data Source=192.168.1.4;Database =BaryNew ;User ID=sa;Password=baryons1"/> <add name="BISConnectionString" connectionString="Data Source=192.168.1.4;Database =Bary ;User ID=sa;Password=baryons1"/> <add name="BaryConnectionString" connectionString="Data Source=WIN-3U37PS1RHVF;Initial Catalog=Bary123;Integrated Security=True" providerName="System.Data.SqlClient"/> </connectionStrings>
<connectionstrings> <add connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=E:\PatientDetails.mdf;Integrated Security=True;User Instance=True" name="Connection" /> <add connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\PatientDetails.mdf;Integrated Security=True;User Instance=True" name="Connection1" /> <add connectionstring="Data Source=.\SQLEXPRESS;AttachDbFilename=G:\PatientDetails.mdf;Integrated Security=True;User Instance=True" name="Connection2" /> </connectionstrings>
From the code you can access like
string=Convert.ToString(ConfigurationManager.ConnectionStrings[0]);OR
string=Convert.ToString(ConfigurationManager.ConnectionStrings[1]);OR
string=Convert.ToString(ConfigurationManager.ConnectionStrings[2]);
try thses links
http://weblogs.asp.net/owscott/archive/2005/08/26/Using-connection-strings-from-web.config-in-ASP.NET-v2.0.aspx[^]
http://www.connectionstrings.com/Articles/Show/store-connection-string-in-web-config[^]
这篇关于关于web.config文件和class.cs的写法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文