本文介绍了web.config文件中的连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 < connectionStrings > < add name = Rama connectionString = Data Source = 192.132.43.34; Initial Catalog = Test-rama; Persist Security Info = True; User ID = rama; Password = *** providerName = 系统.Data.SqlClient / > < / conne ctionStrings > i我正在使用3层架构,但我在web.config文件中提供了这些凭据,我收到连接失败错误... 解决方案 数据源= 190 。 190 。 200 . 100 , 1433 ;网络库= DBMSSOCN; 初始目录= myDataBase;用户ID = myUsername;密码= myPassword; Datasource = ipaddress,端口号; 如果Framework 2.0那么 < appsettings > < add key = myConnectionString value = server = localhost; database = myDb; uid = myUser; password = myPass; / > < / appsettings > 在课堂上 string connStr = ConfigurationSettings.AppSettings( myConnectionString); 在Framework 2.5及以上版本中 < connectionstrings > < add name = myConnectionString connectionstring = server = localhost; database = myDb; uid = myUser; password = myPass; / > < / connectionstrings > 在课堂上 string connStr = ConfigurationManager.ConnectionStrings [ myConnectionString]。ConnectionString; 添加预标签。 [/编辑] web配置文件 < connectionStrings > < add 名称 = myconnecti on connectionString = 数据源= ServerName;初始目录= dbName;用户ID = userId;密码= psw / > < / connectionStrings > 正在读取连接字符串代码隐藏文件: string connStr = ConfigurationManager.ConnectionStrings [ myconnection]。ConnectionString; 已添加 pre 标签。 [/编辑] <connectionStrings> <add name="Rama" connectionString="Data Source=192.132.43.34;Initial Catalog=Test-rama;Persist Security Info=True;User ID=rama;Password=***" providerName="System.Data.SqlClient"/> </connectionStrings>i am using 3 tier architecture ,but i gave these credentials in web.config file,i am getting connection failed error... 解决方案 Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;Datasource=ipaddress,port number;if Framework 2.0 then<appsettings><add key="myConnectionString" value="server=localhost;database=myDb;uid=myUser;password=myPass;" /></appsettings>In Classstring connStr = ConfigurationSettings.AppSettings("myConnectionString");In Framework 2.5 and Above<connectionstrings><add name="myConnectionString" connectionstring="server=localhost;database=myDb;uid=myUser;password=myPass;" /></connectionstrings>In Classstring connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;[Edit member="Tadit"]Added pre tags.[/Edit]web config file<connectionStrings> <add name="myconnection" connectionString="Data Source=ServerName;Initial Catalog=dbName;User ID=userId;Password=psw" /> </connectionStrings>Reading Connection string in code behind file:string connStr = ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString;[Edit member="Tadit"]Added pre tags.[/Edit] 这篇关于web.config文件中的连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-25 20:41