c# - 将 Azure SQL 数据库连接到 ASP.NET 项目

标签 c# sql asp.net azure connection-string

我正在使用 Visual studio 2015。我已在 Azure 上创建了一个数据库并连接到它,并且可以在 SQL 对象浏览器中看到它已连接。

我已从 Azure 仪表板复制连接字符串,并设置数据库的防火墙以允许任何 IP 地址访问数据库。

我的连接字符串是:

static string connString = @"Server=tcp:uvaluedb2.database.windows.net,1433;Initial Catalog=UValueDB2;Persist Security Info=False;User ID=XXXXXXX;Password=XXXXXXXXX;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";

它没有连接到数据库,我收到此消息:

Server Error in '/' Application.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

我可以在VS中查询数据库。

最佳答案

I have created a database on Azure and connected to it and can see it connected in the SQL Object browser.

I had this in my firewall settings though: All 0.0.0.0 255.255.255.255.

看来您已授予从所有 IP 地址访问 SQL Azure 数据库的权限,这应该使您能够从本地运行的应用程序访问 SQL Azure 数据库。请确保您在连接字符串中指定了正确的 SQL 服务器名称“uvaluedb2”。你可以get Connection string来自 Azure 门户。

此外,请尝试创建新的 SQL Azure 数据库并配置防火墙规则,然后从您的应用程序访问它以检查是否会出现相同的问题。

关于c# - 将 Azure SQL 数据库连接到 ASP.NET 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41020929/

相关文章:

c# - 使用 AutoMapper 将字符串列表映射到对象列表

asp.net - Linq 到 SQL : Group By and Sum()

c# - WPF 中网格某些单元格的边框

c# - .net 配置文件 AppSettings : NameValueCollection vs. KeyValueConfigurationCollection

sql - Oracle 数字字符串列和索引

php - 按第一个字符过滤列值?

mysql - 逗号分隔的外键

c# - 图片上传 - 安全问题

asp.net - 如何在 ASP.NET 中混合使用 WebForms 和 MVC

c# - c# 中有没有办法知道用户何时使用应用程序完成文件编辑?