Cannot connect to azure db via SqlConnection

爷,独闯天下 提交于 2019-12-25 03:51:51

问题


I have a webiste hosted on Azure and I have uploaded my db to azure via SSMS 2012 and I can connect to the azure server and db in SSMS and when i create a connection to the db in Database Explorer and test the connection it says it works fine.

I cannot access the management section for the db in azure management portal (I can do this for another db but I have the same problem when accessing that one via the website as well)

I tried giving the Login 'ashley' the db_owner privilege

EXEC sp_addrolemember 'db_owner', 'ashley'

and got this error

Msg 15151, Level 16, State 1, Line 1 Cannot alter the role 'db_owner', because it does not exist or you do not have permission.

This is the connection in the webconfig file

add name="C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2012\PROJECTS\ORGANISER\ORGANISER \APP_DATA\CUSTOMER_DB.MDFConnectionString2" connectionString="Server=tcp:{myserver};Database=C:\Users\User\Documents\Visual Studio 2012\Projects\Organiser\Organiser\App_Data\Customer_db;User ID=ashley;Password={mypassword};Trusted_Connection=False;Encrypt=Tr‌​ue;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" /

and the connection string i use to reference this in the code behind

string Connection = @"C:\USERS\USER\DOCUMENTS\VISUAL STUDIO 2012\PROJECTS\ORGANISER\ORGANISER\APP_DATA\CUSTOMER_DB.MDFConnectionString2";

I cannot understand why I can access the db in SSMS and in database explorer but not when the website is running.

I am also new to Azure, ASP and MSSQL in general


回答1:


Depending on your account configuration, you may need to add an allowed port/IP range to azure DB configuration. Go to Data "SQL Databases" properties - Configure - allowed ip addresses - Add your IP range

and you'll be able to connect.




回答2:


Your connection string is pointing to a local mdf file. Change the Database= to the name you assigned to your db on Sql Azure.




回答3:


Make sure you are running the T-SQL query in the correct database context, select your user database in dropdown list.



来源:https://stackoverflow.com/questions/15792124/cannot-connect-to-azure-db-via-sqlconnection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!