在appconfig中使用通用连接字符串 [英] Using common connectionstring in appconfig

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

问题描述

亲爱的所有
Iam正在使用由大约45个表单组成的windowsformapplication,并且数据库是MS Acess,为了简化编码,我在每个Forms中都声明了连接字符串,如下所示

Dear all
Iam working with an windowsformapplication which consist of almost 45 forms and the database is MS Acess for the ease of Coding I had declared connectionstring as below in every Forms

public partial class LoginForm : Form
   {
    private String connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\NauferTransactionDemoDB.accdb";

       public LoginForm()
       {
           InitializeComponent();
       }}



但是现在项目快要结束了,我想在appconfig中声明此连接,以便我可以轻松更改它
我是编程新手,并且面对相同的问题

我用过




But now project is almost over and I want to make this connection declared in appconfig so that I can change it easily if I want
Iam new to programming and is facing the problem with the same

i used


<configuration>
  <connectionstrings>
    <add name="connect">
         connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\NauferTransactionDemoDB.accdb";User Instance=True"
    />
  </add></connectionstrings>
</configuration>



但是当我尝试用下面的形式调用它时
字符串cString = ConfigurationManager.ConnectionStrings ["connect"]. connString;
我在connectionstring上遇到异常

谁能帮忙

[edit]将我的内容视为纯文本..."选项已禁用-OriginalGriff [/edit]



But when i try to call this in Forms like below
String cString = ConfigurationManager.ConnectionStrings["connect"]. connString;
I get Exception at connectionstring

Can any one help

[edit]"Treat my content as plain text..." option disabled - OriginalGriff[/edit]

推荐答案

<add name="Name" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\NauferTransactionDemoDB.accdb";User Instance=True" />



http://msdn.microsoft.com/en-us/library/ms254494 (v = vs.80).aspx [



http://msdn.microsoft.com/en-us/library/ms254494(v=vs.80).aspx[^]


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

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