0

我想从我的Web角色实例连接到Azure的SQL数据库时,以下问题:Azure的SQL数据库连接从Web角色的问题

[SqlException (0x80131904): 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]

我的连接字符串:

metadata=res:///MyModel.csdl|res:///MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string='data source=SOMETHING.database.windows.net,1433;initial catalog=DBNAME;User [email protected];Password=PASS!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;'

我还将数据库与我的Web角色链接并添加了允许的IP。我可以使用SQL Server Management Studio进行连接。

这里可能还有其他问题吗?

+1

你检查在门户网站你'允许的IP addresses'列表? – haim770

+0

这没有奏效。但现在看来它不会连接到我的模拟器中。但如果我运行我的Web应用程序项目,它连接正常。 – davenewza

+0

你的'allowd ip addresses'中是否有条目? – haim770

回答

0

我不得不添加MultipleActiveResultSets=True到连接字符串:

metadata=res:///MyModel.csdl|res:///MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string='data source=SERVER.database.windows.net,1433;initial catalog=DBNAME;User [email protected];Password=PASS;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True'