Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Azure上的SQL连接功能仅适用于本地主机_C#_Sql Server_Visual Studio_Azure_Azure Functions - Fatal编程技术网

C# Azure上的SQL连接功能仅适用于本地主机

C# Azure上的SQL连接功能仅适用于本地主机,c#,sql-server,visual-studio,azure,azure-functions,C#,Sql Server,Visual Studio,Azure,Azure Functions,我在VisualStudio上运行了azure函数。该函数从托管在Azure(SQL Server)上的SQL数据库返回一些数据,在localhost上,一切正常,但当我将其发布到Azure时,它返回500个错误 在Azure SQL上,我检查了从其他Azure服务和我的IP地址进行的访问 local.settings.json { "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "", "AzureWeb

我在VisualStudio上运行了azure函数。该函数从托管在Azure(SQL Server)上的SQL数据库返回一些数据,在localhost上,一切正常,但当我将其发布到Azure时,它返回500个错误

在Azure SQL上,我检查了从其他Azure服务和我的IP地址进行的访问

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "AzureWebJobsDashboard": ""
  },
  "ConnectionStrings": {
    "MySqlConnectionString": {
      "ConnectionString":
        "Server=tcp:webappgtoproject.database.windows.net,1433;Initial Catalog=database;Persist Security Info=False;User ID=xxx;Password=yyy;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;",
      "providerName": "System.Data.SqlClient"

    }
  }
}
代码


如果没有SQL connect,它在Azure上可以正常工作。

local.settings.json
文件仅在本地运行时使用。您需要在应用程序设置中定义连接字符串(单击应用程序功能,然后选择
App Settings
link)
string str = ConfigurationManager.ConnectionStrings["MySqlConnectionString"].ConnectionString;

using (SqlConnection conn = new SqlConnection(str))
{
    conn.Open();

    // Check PC
    string text2 = "command text";

    using (SqlCommand cmd = new SqlCommand(text2, conn))
    {
    }

    return true;
}