ramki_ramakrishnan
ramki_ramakrishnan

Reputation: 199

Unable to connect to Local SQL database from app.config in windows form application

i am trying to connect my local MySQL database to my windows form application using app.config. but i am keep on getting the below mentioned Exception.Can anyone help me please. Exception :

App.config be like :

<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>

Upvotes: 2

Views: 337

Answers (3)

Guffa
Guffa

Reputation: 700152

The tag name is case sensetive, it should be:

<connectionStrings>
  ...
</connectionStrings>

Note: System.Data.SqlClient is the provider for Microsoft SQL Server, not MySQL.

Upvotes: 4

Ahuman
Ahuman

Reputation: 762

Two things to note here.

  1. You are talking about MySql, but connection string looks like for MSSql.
  2. When you initialize your SqlConnection object, make sure you are giving the right connection string name MyConnectionstringname

Upvotes: 0

Sam
Sam

Reputation: 2917

You have two end tags </configSections>. Remove the one before <connectionstrings>

And, <connectionstrings> is case sensitive. It should be <connectionStrings>

Upvotes: 0

Related Questions