从app.config文件中检索连接字符串 [英] retrive connection string from app.config file

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

问题描述

先生,

我从app.config文件中检索连接字符串时遇到问题.我使用代码
C#代码

Sir,

I have problem in retrieving connectionstring from app.config file. I use the code
c# code

this.constring = ConfigurationManager.ConnectionStrings["CountryConstring"].ConnectionString;





//config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
  <connectionStrings>
    <clear/>
     <add name="sConstring"

     providerName="System.Data.SqlClient"

     connectionString="Data Source=Dnyan-PC;Initial Catalog=DB_REGISTRATION;Integrated Security=True" />
  </connectionStrings>

</configuration>


但以上内容在.net4中无法用于窗口应用程序
请帮助

thanx,
[电子邮件已删除]
dnyaneshwar


请不要在这样的问题中输入您的电子邮件,因为它仅是垃圾邮件的邀请.当有人回答您的问题时,您会收到一封发送到您注册地址的电子邮件.


but above not work in .net4 for window application
please help if any

thanx,
[Email Removed]
dnyaneshwar


Please do not put your email into your question like this as it is nothing more than an invitation for spam. When someone responds to your question you will get an email sent out to the address you signed up with.

推荐答案

您的app.config连接字符串部分是什么样的?将其添加到您的问题中,以便我们获得需要回答的所有信息.

将此用作模板: http://msdn.microsoft.com/en-us/library/ms178411. aspx [^ ]
What does your app.config connection strings section look like? Add that to your question so that we have all the information we need to answer.

Use this as a template: http://msdn.microsoft.com/en-us/library/ms178411.aspx[^]




在您发布的代码中,yo
1.在app.config文件中包含连接字符串名称为"sConstring".
2.在您的cs文件中,使用"CountryConstring"进行检索.

如果我错了,您能再详细说明您的问题吗?
Hi,

In your posted code, yo
1. in app.config file contains connection string name as "sConstring".
2. And in your cs file you retrieve with "CountryConstring".

can you more elaborate your question if i m wrong.


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

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