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

2

11

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.

Woodworm answered 2/8, 2017 at 4:49 Comment(0)
P
13

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>
Panpipe answered 2/8, 2017 at 4:59 Comment(0)
G
6

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

Gaither answered 18/4, 2018 at 11:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.