How to add Azure SQL Server connection string to app.config in Windows Forms?

mabel picture mabel · Aug 2, 2017 · Viewed 17.2k times · Source

I'm trying to add an Azure SQL Server connection string into my app.config file, but there are red underlines all over the connection string when I try to copy and paste it from Azure. I'm using Windows Forms in Visual Studio.

Here is my connection string:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
        <add name="AddSales"
             Server="tcp:Sales99.database.windows.net,1433;Initial" Catalog="Sales;Persist" Security="" Info="False;User" ID=""{your_username};Password=""{your_password};MultipleActiveResultSets=""False;Encrypt=""True;TrustServerCertificate="False;Connection" Timeout="30"
             providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

Is there a way to fix this issue? Please advise.

Answer

marc_s picture marc_s · Aug 2, 2017

Your config is just plain wrong - you need to have an attribute connectionString in your config that contains all the details about the connection - something like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <connectionStrings>
        <add name="AddSales"
             connectionString="Server=tcp:Sales99.database.windows.net,1433;Initial Catalog=Sales;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30"
             providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>