如何将Azure SQL Server连接字符串添加到Windows窗体中的app.config?

问题描述:

我想将Azure SQL Server连接字符串添加到我的app.config文件中,但是当我尝试从Azure中复制并粘贴时,整个连接字符串都会出现红色下划线。我在Visual Studio中使用Windows窗体。如何将Azure SQL Server连接字符串添加到Windows窗体中的app.config?

这里是我的连接字符串:

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

有没有办法解决这个问题?请指教。

你的配置是完全错误 - 你需要在你的配置包含所有有关连接的详细信息的属性connectionString - 这样的事情:

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