会话中的连接字符串 [英] connectionstring in session

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

问题描述

我在访问应用程序中的连接字符串时遇到问题.我已经在会话中配置了这样的连接字符串.

I have a problem i want to access connection string in my app. i have configured connection string in session like this.

<configuration>
    <system.web>
        <roleManager enabled="true" />
        <authentication mode="Forms" />
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.web>

        <sessionState mode="SQLServer" sqlConnectionString="Data Source=Sreekanth; Integrated Security=True; Database=Northwind" sqlCommandTimeout="30" cookieless="UseUri" timeout="20"></sessionState>
    </system.web>

</configuration>



我想在我的应用程序中执行更新插入删除操作,我想访问此连接字符串.我不知道怎么办,请帮助我谢谢.



i want to do update insert delete in my application i want to access this connection string. how to do i am not getting idea please help me thank you.

推荐答案

SessionState为当前应用程序配置会话状态设置.

SessionState configures the session state settings for the current application.

<sessionstate mode="Off|InProc|StateServer|SQLServer">
              cookieless="true|false"
              timeout="number of minutes"
              stateConnectionString="tcpip=server:port"
              sqlConnectionString="sql connection string"
              stateNetworkTimeout="number of seconds"/></sessionstate>



访问连接字符串:

.NET 2.0配置文件中的连接字符串
在appSettings位置中,添加一个名为您想要引用连接字符串的名称的键.



To access Connection String:

Connection string in .NET 2.0 config file
In the appSettings location, add a key named whatever you like to reference your connection string to.

<appSettings>
<add key="myConnectionString" value="server=localhost;database=myDb;uid=myUser;password=myPass;" />
</appSettings>



要从代码读取连接字符串,请使用ConfigurationSettings类.



To read the connection string from code, use the ConfigurationSettings class.

string connStr = ConfigurationSettings.AppSettings("myConnectionString");


现在,您已将连接字符串从web.config加载到代码中的字符串变量中.

.NET 3.5(及更高版本)配置文件中的连接字符串
不要在web.config中使用appsettings.而是使用web.config中的connectionStrings部分.


Now you have the connection string loaded from web.config into your string variable in code.

Connection string in .NET 3.5 (and above) config file
Do not use appsettings in web.config. Instead use the connectionStrings section in web.config.

<connectionStrings>
<add name="myConnectionString" connectionString="server=localhost;database=myDb;uid=myUser;password=myPass;" />
</connectionStrings>


要将连接字符串读入代码中,请使用ConfigurationSettings类.


To read the connection string into your code, use the ConfigurationSettings class.

string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;


看看

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

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