【问题标题】:Unable to connect to Local SQL database from app.config in windows form application无法从 Windows 窗体应用程序中的 app.config 连接到本地 SQL 数据库
【发布时间】:2015-04-18 02:36:00
【问题描述】:

我正在尝试使用 app.config 将我的本地 MySQL 数据库连接到我的 Windows 窗体应用程序。 但我不断收到下面提到的异常。谁能帮助我。 例外:

App.config 是这样的:

<configuration>
    <connectionstrings>
        <!--<add name ="support_KB" connectionstring="server= .\sqlexpress;database=kbase_support;Integrated Security=SSPI" />-->
        <add name ="MyConnectionstringname"
             providerName="System.Data.SqlClient"
             connectionstring="Data Source=.\sqlexpress;Initial Catalog=kbase_support;Integrated Security=SSPI" />
    </connectionstrings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>

【问题讨论】:

    标签: c# winforms ado.net connection-string app-config


    【解决方案1】:

    标签名称区分大小写,应该是:

    <connectionStrings>
      ...
    </connectionStrings>
    

    注意:System.Data.SqlClient 是 Microsoft SQL Server 的提供者,而不是 MySQL。

    【讨论】:

      【解决方案2】:

      你有两个结束标签&lt;/configSections&gt;。删除&lt;connectionstrings&gt;之前的那个

      而且,&lt;connectionstrings&gt; 区分大小写。应该是&lt;connectionStrings&gt;

      【讨论】:

        【解决方案3】:

        这里有两点需要注意。

        1. 您说的是 MySql,但连接字符串看起来像 MSSql。
        2. 初始化 SqlConnection 对象时,请确保提供正确的连接字符串名称 MyConnectionstringname

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-02-06
          • 1970-01-01
          • 2014-10-21
          • 2022-01-26
          • 2021-07-24
          • 2017-06-10
          相关资源
          最近更新 更多