Windows Azure Web Service,无法连接到 SQL 数据库

本文关键字:连接 SQL 数据库 Azure Web Service Windows | 更新日期: 2023-09-27 18:35:45

我正在研究这个问题一段时间,我不知道该怎么办了......所以这就是问题所在。

我有一个Azure Webservice,它可以在本地完美运行。它应该连接到Azure SQL数据库(我使用相同的ConnectionString进行调试和Azure......所以它应该是正确的)

使用智能跟踪,我发现以下错误:

Requested registry access is not allowed.
System.IO.FileNotFoundException Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=Neutral....
System.Data.Entity.Core.ProviderIncompatibleException
System.Data.SqlClient.SqlException    A network-related or instance-specific error occured while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct... (This about 50 times)
System.Threading.WaitHandleCannotBeOpenedException              No handle of the given name exists.
System.Security.SecurityException          Requested registry access is not allowed
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironmentException        error 
System.Threading.WaitHandleCannotBeOpenedException            No handle of the given name exists.

(异常堆栈、最新堆栈、最旧堆栈)

在我的 web.config 中,我像这样设置 EF 和 ConnectionString:

<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="EntityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework" requirePermission="false"/>
</configSections>
<connectionStrings>
  <add name="DefaultConnection" connectionString="Server=SERVER.database.windows.net;Database=LeagueMetaDatabase;User ID=USER@ksew7pk8ad;Password=PW;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>

我还停用了EF程序集的"特定版本"并激活了"复制本地"。我在服务器上检查了服务的 bin 文件夹,dll 在那里。

该服务使用了很多异步,但如前所述,它可以在本地工作。我还在服务器上安装了.NET 4.5.1,以确保这不是问题所在

//编辑首先,感谢到目前为止的所有帮助!

我试图缩小问题范围......重建孔项目并试图找到不起作用的东西。异步任务似乎无法读取 Azure 服务器云上的 Web.config 中的连接字符串。在模拟器中,它可以工作。我将连接字符串硬编码到上下文中,它正在以这种方式工作。

任何人都可以告诉我是什么创造了这种行为,以及我如何将其放回 Web.config 中?

Windows Azure Web Service,无法连接到 SQL 数据库

如何将解决方案部署到 Azure?您使用的是云服务还是网站?如果您正在运行 Azure 网站,则问题可能与 web.config 和 Azure 网站中的连接字符串名称相同有关。如果是这种情况,可能需要尝试重命名在 Azure 管理门户中为网站定义的连接字符串。这可以通过"配置管理"页完成。

希望这有帮助。

数据库和云服务是否位于同一数据中心? 如果没有,请通过 Azure 控制面板链接资源和/或确保已在"数据库配置"部分中启用"允许 Azure 服务连接"。

另外,请确保您的服务器连接指定了"tcp" - Windows Azure SQL 数据库服务仅适用于 TCP 端口 1433。若要从计算机访问 SQL 数据库,请确保防火墙允许 TCP 端口 1433 上的传出 TCP 通信(来自连接到 Windows Azure SQL 数据库的指南)。 如果从数据库仪表板页获取 ADO 连接字符串,应会看到:

Server=tcp:{your_servername}.database.windows.net,1433;Database={your_database_name};User ID={your_userid};Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;

首先,感谢到目前为止的所有帮助!

我试图缩小问题范围......重建孔项目并试图找到不起作用的东西。异步任务似乎无法读取 Azure 服务器云上的 Web.config 中的连接字符串。在模拟器中,它可以工作。我将连接字符串硬编码到上下文中,它正在以这种方式工作。

任何人都可以告诉我是什么创造了这种行为,以及我如何将其放回 Web.config 中?