Pages

Showing posts with label Single User. Show all posts
Showing posts with label Single User. Show all posts

Friday, January 2, 2015

Contained Database–A new feature in SQL SERVER 2012 TIP #81

While working on a project sometimes it happened that we need to shift the database from one server to another due to various reason (sometimes it is only money Smile ).

We are aware that this easy step take backup and restore another machine but glitch is what about the users which have access to the database ?

Now , the next step of us to create each individual user on newly database server which is very tedious job sometimes.

In SQL SERVER 2012 a new feature introduced by Microsoft which is Contained Database.  This feature allows us to move meta data as well with database backup.

Let me explain it in more detail what I mean to say here. A contained database is a feature which isolate database from other database and from SQL SERVER host for authentication which means now the authentication can be done on database level.

For example you want to move a in house Employee management system which has around 100 users which access this database so if the database in contained enabled then in that case we do not have to create new users on another sever.

Now let me explain here how to enable this feature

Step 1:- Enable this feature on server level by right clicking on server and from property TAB

ServerProperties

We can enable this feature by following command as well.

ContainedFeatureEnable

EXEC sp_configure 'show advanced', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'contained database authentication', 1
GO
RECONFIGURE
GO
GO

Step 2:- Now right click and go to property TAB of database on which we have to enable Containment Type feature

Database_Level_ContainmentType

We have to enable this feature and set the value Partial

We can enable this feature via SQL command

ALTER DATABASE IndiandotnetDB SET CONTAINMENT = PARTIAL

Once we have enable above this feature we are good to go.

Now when you create user on database you can easily move this database with the META DATA which means user.

Warning :- If you see the image below you will find Replication, change data Capture,Change Tracking are not supported contained databases.

Warning

so if you are using Replication, change data capture, change tracking please avoid enabling this feature and use traditional way of creating user.

I hope this feature might help you somewhere.

Thanks

RJ

Monday, June 2, 2014

How to find what is currently running on your SQL SERVER? TIP # 12


When we are keen to know that what is currently running on SQL SERVER for analysis purpose then with the help of below SQL statement we can easily find those statements, Stored procedure, status etc.

Go
SELECT [Spid] = session_Id
, ecid
, [Database] = DB_NAME(sp.dbid)
, [User] = nt_username
, [Status] = er.status
, [Wait] = wait_type
, [Individual Query] = SUBSTRING (qt.text,
er.statement_start_offset/2,
(CASE WHEN er.statement_end_offset = -1
THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2
ELSE er.statement_end_offset END -
er.statement_start_offset)/2)
,[Parent Query] = qt.text
, Program = program_name
, Hostname
, nt_domain
, start_time
FROM sys.dm_exec_requests er
INNER JOIN sys.sysprocesses sp ON er.session_id = sp.spid
CROSS APPLY sys.dm_exec_sql_text(er.sql_handle)as qt
WHERE session_Id > 50 — Ignore system spids.
AND session_Id NOT IN (@@SPID) — Ignore this current statement.
ORDER BY 1, 2
Go

Enjoy !!!


Sunday, June 1, 2014

How to set database as multi user TIP #11

 

As we mention in  TIP 10  to set database user as Single user now to make this available again for all the user or multi user we need to do following

ALTER DATABASE FriendsDB
SET MULTI_USER 
WITH  NO_WAIT;

GO

Here when we run above command  FriendsDB again changed to MULTI USER.

Here NO_WAIT means not wait for statement with immediate response.

When we run this command database again change to multi user as shown in below fig

Multi_User_Db

 

Enjoy !!!

How to set database as Single User TIP #10

Sometimes it is require to  set database as single user for maintenance or other recovery purpose.

We need to write following statement

GO

ALTER DATABASE FriendsDB
SET SINGLE_USER 
WITH  ROLLBACK IMMEDIATE;

GO

Here ROLLBACK IMMEDIATE  means if any transaction going on by other user then Rollback that data.

See below snap for more detail

Single_User_DB

SEt_Single_User_Result

Enjoy !!!