简体   繁体   English

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

[英]Connecting Azure SQL database to ASP.NET project

I'm using Visual studio 2015. I have created a database on Azure and connected to it and can see it connected in the SQL Object browser. 我正在使用Visual Studio 2015.我在Azure上创建了一个数据库并连接到它,并且可以在SQL对象浏览器中看到它已连接。

I have copied in my connection string from the Azure dashboard and set the firewall for the database to allow any IP address access the database. 我已从Azure仪表板复制了我的连接字符串,并为数据库设置了防火墙,以允许任何IP地址访问数据库。

My connection string is: 我的连接字符串是:

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;";

It is not connecting to the database and i get this message: 它没有连接到数据库,我收到此消息:

Server Error in '/' Application. '/'应用程序中的服务器错误。

A network-related or instance-specific error occurred while establishing a connection to SQL Server. 建立与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. 验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (提供程序:SQL网络接口,错误:26 - 查找指定的服务器/实例时出错)

I can query the database in VS. 我可以在VS中查询数据库。

I have created a database on Azure and connected to it and can see it connected in the SQL Object browser. 我在Azure上创建了一个数据库并连接到它,可以看到它在SQL对象浏览器中连接。

I had this in my firewall settings though: All 0.0.0.0 255.255.255.255. 我在防火墙设置中有这个:所有0.0.0.0 255.255.255.255。

It seems that you give access to SQL Azure database from all IP addresses, which should enable you to access SQL Azure database from your application running on local. 您似乎可以从所有IP地址访问SQL Azure数据库,这使您可以从本地运行的应用程序访问SQL Azure数据库。 Please make sure if you specify the correct SQL server name “ uvaluedb2 ” in your connection string. 请确保在连接字符串中指定了正确的SQL服务器名称“ uvaluedb2 ”。 And you could get Connection string from Azure portal. 您可以从Azure门户获取连接字符串

Besides, please try to create new SQL Azure database and configure firewall rules, and then access it from your application to check if same issue will appear. 此外,请尝试创建新的SQL Azure数据库并配置防火墙规则,然后从您的应用程序访问它以检查是否会出现相同的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM