Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 762
mabel Avatar asked Aug 02 '17 04:08

mabel


2 Answers

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>
like image 115
marc_s Avatar answered Oct 14 '22 07:10

marc_s


I also had this issue when I try to copy & paste connection string from the Azure database. This is connection string that worked for me.

Server=tcp:[serverName].database.windows.net;Database=myDataBase; User ID=[LoginForDb]@[serverName];Password=myPassword;Trusted_Connection=False; Encrypt=True;

This also works.

<add name="ConnectionStringName"
    providerName="System.Data.SqlClient"
    connectionString="Data Source=tcp:ServerName.database.windows.net,1433;Initial Catalog=DatabaseName;Integrated Security=False;User Id=username@servername;Password=password;Encrypt=True;TrustServerCertificate=False;MultipleActiveResultSets=True" />

If you need additional info, please visit these sites:
https://www.connectionstrings.com/sql-azure/
https://msdn.microsoft.com/en-us/library/jj653752(v=vs.110).aspx

like image 23
DxTx Avatar answered Oct 14 '22 08:10

DxTx