June 12, 2014 at 3:30 am
how do i change connection database from master database to own database please
June 12, 2014 at 3:32 am
From an application? When you connect to Management Studio? Something else?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 12, 2014 at 7:07 am
You can change the default database in the properties of the LOGIN you are using. This is the most helpfull way if you only need to access one single database.
You can execute the "USE [your_databasename];" command before your SQL statements if you need to change the scope to another database.
In most (or all?) connection strings (like for an ODBC connection) you can specify the desired database you initially want to connect to.
June 12, 2014 at 10:24 pm
This was removed by the editor as SPAM
June 12, 2014 at 10:50 pm
sqladmin 33439 (6/12/2014)
how do i change connection database from master database to own database please
In T-SQL there are two main options, either use a system stored procedure sys.sp_defaultdb or ALTER LOGIN, recommend the former as it adds validity checks for the login and the database name. It also checks for open transactions.
😎
/* The command for changing the default db
*/
ALTER LOGIN [login_name] WITH DEFAULT_DATABASE = [database_name];
/* System procedure which adds validity checks before executing
the command above
*/
EXEC sys.sp_defaultdb [login_name], [database_name];
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply