webconfig连接字符串 [英] webconfig connection string

查看:142
本文介绍了webconfig连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 我有一个用户连接到数据库的Web表单。我想在登录Web表单时使用会话变量。我想将用户名和密码传递给webconfig文件连接,以便可以使用
thier登录凭据对数据库进行身份验证。这种方式当他们在应用程序中使用他们的用户名和密码进行交易时?

 I have a web form that users connect to a database. I want to use session variables when they log into the web form. I would like to pass the username and password to the webconfig file connection so that could authenticate into the database using thier login credentials. This way when they do a transaction in the app its using their username and password?

我该怎么办?

How can I do this?

< add name =" ColSec" connectionString =" Data Source = dev; Initial Catalog = dev2; User ID = DMS; Password = pswd。" providerName =" System.Data.SqlClient" />

<add name="ColSec" connectionString="Data Source=dev;Initial Catalog=dev2;User ID=DMS;Password=pswd." providerName="System.Data.SqlClient"/>

推荐答案

实际上你无法在web.config文件中传递任何动态数据。相反,您可以使用ConfigurationManager在C#代码中动态设置连接字符串。在那里你可以动态创建连接字符串并使用它。

Actually you cannot pass any dynamic data in the web.config file . Instead you can use ConfigurationManager to set the connection string dynamically in your C# code . There you can dynamically create connection string and use it .

string connstr ="" Data Source = dev; Initial Catalog = dev2; User ID =" + uid +" ;;密码= QUOT; +通+ QUOT;" providerName =" System.Data.SqlClient";

string connstr = ""Data Source=dev;Initial Catalog=dev2;User ID="+uid+";Password="+pass+"." providerName="System.Data.SqlClient";

像这样,uid和pass按你的意愿动态设置!

Like this , where uid and pass are set dynamically as you wish!

告诉我如果有任何问题!

Let me know if in any problem !


这篇关于webconfig连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆