Changing the default database for a SQL Azure login

余生长醉 提交于 2019-12-06 16:32:43

问题


I would like to change the default database for a login to support software that can access SQL Azure but does not allow easy alteration of a connection string. It appears that SQL Azure defaults to the master database.

I've already considered:

  • Stored procedures. I can't find a stored procedure that does this (sp_defaultdb is not implemented in SQL Azure as far as I can tell)

  • Alter Login. ALTER LOGIN does not permit the DEFAULT_DATABASE option.

  • SSMS. SSMS doesn't seem to allow much user control through the interface for SQL Azure.

Ideas?


回答1:


Connection String:

Server=tcp:[serverName].database.windows.net;Database=myDataBase;User ID=[LoginForDb]@[serverName];Password=myPassword;Trusted_Connection=False;Encrypt=True;

You can change connect default database, when you write 'Database' property at connection string.

SSMS is connect to database box which is option->secont tab at conecct dialog.




回答2:


As you already discovered the DEFAULT_DATABASE option is not available in SQL Azure. So if you cannot change the connection string of your application in which you would normally specify the database name, you are stuck to master.

However... is it possible to create an ODBC connection, and configure your application to use ODBC? Using ODBC would allow you to specify a default database.




回答3:


You can easily change the default database when loging in with SSMS. Click the Options button on the Login Dialog then click on the Connection Properties tab. In the "Connect to database" box enter the name of your database.




回答4:


In my case I managed to do it by creating a login directly in the master database:

CREATE LOGIN newlogin WITH password='password'
GO

CREATE USER newlogin FOR LOGIN newlogin WITH DEFAULT_SCHEMA=[dbo]
GO

Then I created a user in the database I wanted to gain access to:

CREATE USER newlogin FOR LOGIN newlogin WITH DEFAULT_SCHEMA=[dbo]
GO

At last adding it to a role in the particular database to gain the right permissions:

Alter role db_owner add member newlogin

Hope this works for you too.




回答5:


You have to use use following to be able to change "default" Database

  1. Use "SQL Server Native Client 10.0" or higher instead on using "SQL Server as Driver
  2. Use full user id like UserName@AzureConnnectString

For me it is NorthWind@w6ywertsd8h.database.windows.net

More details here http://debugmode.net/2011/04/22/connecting-microsoft-access-to-sql-azure/




回答6:


By far the easiest way in SSMS is to use the additional parameters tab and supply the initial catalog, e.g.




回答7:


Another option is to create a mapped user in the master database and the hosted database. This will allow SSMS to connect to the server and use master as the default db, then the user can open the database. I am not a DBA so I do not know the implications of this, but that is how I solved it. My database is just being used for a POC project so it doesn't have many security requirements.



来源:https://stackoverflow.com/questions/8859067/changing-the-default-database-for-a-sql-azure-login

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