.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

SMO Database in Single User mode issues

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :

I am trying to use the SMO library and setting the single user mode. Here is a simple example illustrating my issue.

The below code will fail the first time. Saying "Invalid object name TestTable". Eventhough that table does exist and so does the DB. However, if you run it again (now the DB is already in single user mode) everything works fine. Also, if you remove the code that alters the db user mode everything works fine. I am assuming the problem must exist with the single user mode and utilizing the correct db connection. I have tried flipping the AutoDisconnectMode and NonPooledConnection but that hasn't help. Any help would be appreciated.

Sample code

SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(); 

sb.Password = "P@ssword!"; 

sb.UserID = "testuser"; 

sb.DataSource = @".\mssql2008"; 

sb.InitialCatalog = "TestDB"; 

ServerConnection serverConn = new ServerConnection(); 

//serverConn.AutoDisconnectMode = AutoDisconnectMode.NoAutoDisconnect; 


View Complete Post

More Related Resource Links

Database Corrupted - Can't get db in single user mode

I have two SQL 2008 R2 databases running on a 64-bit development Machine :
I have created Synonyms in MyDatabase (Table1, Table2, Table3) for three tables in the IMS database.
I am experiencing very poor performance using these Synonyms from my application so I am trying to troubleshoot the problem.
I tried to run "DBCC CHECKDB (IMS,  REPAIR_ALLOW_DATA_LOSS)" by performing the following steps
  1. Used Services to stop the processes (Instance, Agent, Browser, Integration Services 10.0, VSS Writer)
  2. Ran cmd.exe "As Administrator"
  3. cd C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\Binn
  4. ran sqlservr.exe -m -s SQLEXPRESS (output says it started in single user mode)


  1. Ran cmd.exe "As Administrator"
  2. cd C:\Program Files\Microsoft SQL Server\100\Tools\Binn
  3. ran sqlcmd.exe -S D

SQL Server 2000 Database in "single user mode"


Hi all,

I've an old production database server with SQL Server 2000 SP4, that runs from 6 years. Now sometimes I find that the production database goes in "single user mode". Why? My error logs don't help me.

Is realtime SQL Server Replicated database usable realtime (not offline / single user mode)


Is SQL Server replicated (destination) database replicated by SQL Server Replication fully usable? Meaning it's not just for Disaster Recovery but is fully usable from various say BI / Reporting purposes.

In the essence it is exactly same as other replication engines and the destination database is very much usable and not just offline / single user mode.



SQL 2008 R2 clustered instance does not start in single user mode

Hi I am testing the startup of a SQL 2008 R2 clustered instance (Windows 2008 R2) using single user mode but it fails with : Error: 17058, Severity: 16, State: 1. initerrlog: Could not open error log file ''. Operating system error = 3(The system cannot find the path specified.) - I am running the following command from the default sql installation : C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL01\MSSQL\Binn>sqlservr.exe -c -m -s SQL01 - The cluster service on the passive node has been shutdown. - The SQL Server and SQL Agent services have been set to offline in Failover Cluster Manager. Any assistance greatly appreciated. Regards, PK    

Websites using shared libraries and single common database issues


Hi everyone,

    I will be having several websites using the same shared libraries(Domain,Repository,etc..) and one single database.

 Later on i want to add another website with some added functionalities and added tables,columns ,etc in the database. The issue is that when i go deploy the last website, i will have to update all my other projects so that they work.

Is there any work around this process? Or is this the right way of doing things? 

Thx everyone

coming out of single user mode



How to come out of single user mode in sql server


Unattended Install leads to Single User Mode and Access Denied


Hi everyone,

I'm trying to install SQL 2008R2 (full) with an answerfile.. in my answerfile I have specified a local group that should be SQLAdministrators.. in the log I see that the group is validated

2011-04-07 23:06:27 Slp: Sco: Attempting to get sid for user account ZEW-V-913BC072\SSPSQLAdmins
2011-04-07 23:06:27 Slp: Sco: GetSidForAccount normalized accountName ZEW-V-913BC072\SSPSQLAdmins parameter to SSPSQLAdmins
2011-04-07 23:06:27 AS: Data: SID = S-1-5-21-2763175129-1897282573-4278807499-1019
2011-04-07 23:06:27 AS: Result: Success
2011-04-07 23:06:27 AS: Result: Valid

The only thing i see in the log is:

2011-04-07 23:43:59 Slp: Message: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding..
2011-04-07 23:43:59 Slp: Inner exception:
2011-04-07 23:43:59 Slp:  Exception: System.Data.SqlClient.SqlException.
2011-04-07 23:43:59 Slp:  Source: .Net SqlClient Data Provider.
2011-04-07 23:43:59 Slp:  Message: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding..
2011-04-07 23:43:59 Slp: Error: Action "SqlEngineDBStartConfigAction_install_configrc_Cpu64" failed during execution.

I also noticed that it takes at least two connections before th

MS SQL Server: Disconnect Users From Database - Kill User Session

If you ever wanted to restore your database from a SQL backup file (.bak), but there are still users connected to your database, the backup operation will fail causing the error: Exclusive access could not be obtained because the database is in use.

Linq - add data to database then email user the details


Hi all

I'm not sure how to structure the code for this but what I want to do is be able to add data to a database, and once this has completed successfully, then email the user to say the details have been added successfully to the database.

I need to:

1. Check that the relevant data has been added into the database then

2. Email the details of the relevant data when completed. 


Thanks in advance for your help,




update user status in database when ever user logoff


actually i came across this senario for new project where userstatus must change to log off when ever he do fallowing activity.I have maintain user status when he log in to web based system.

Activities are


1.user click log off

2.or user click browser close button or close brwoser tab.

3.or Fource fully shut down his Pc

I am able to get first 2 but not the last one.I googled it but not get any satified ans for that.

I m looking for guidens for this. Any help is grate help for me as i want it.And also other suggesstion also welcomed.

thanks in advance


How to fill out a form as another user , while using profiles database


I have created an InfoPath 2007 form. It works great.. I have 5 data connections to sharepoint lists and profile's database. The form displays public data (profile database) about the user, such as name, manager.. etc.

What I would like to do is have an option on the form that says " If you are not this person , click here" , manually type the persons last name , and bring up their information.

Basically , there are some people who will have someone else fill the form out for them. But I don't want them to be giving out their username and password to the system.

I want the ability to fill out a form as another user without logging off sharepoint. 

=User!UserID from windows authentication using table from another database



i'm using sql server 2005, sql server business intelligence development studio for my reports and deploy them in my wss3.0 site.

what i'm trying to do is i'm trying to restrict wich users can see specific data within a report.

now, the thing is. the report gets the data out of my DB1 database and my windows authenticated user are in the WSS_content database.

when i deploy my report in my wss3 site. it gets the user that is loged in. but of course it does not display any data because the tables are not in the same database.

does someone knows how to do this?

Create user is creating aspxxxx.mdf database in my app_data folder


I had already setup roles for my pages and requirements call for ability to manage and create users.

So i was looking at code that allows you to do so using membership, even though i got the page to work, it was creating a database in my app_data folder.. i already have SQLExpress setup with the asp schema, but cant figure out how to get my application to use that instead of creating the db in the folder?

What am i missing or doing wrong?

I have the following setup in my web.config file..

		<authentication mode="Windows"/>
			<deny users="?"/>
        <add name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

Facing MSDTC related issues while archiving data from one database server machine to another databas

I have a question with respect to distributed transactions when carried out between two database server machines on the same network.   Consider there are two database server machines \SOURCE_DATABASE_SERVER\ and \DESTINATION_DATABASE_SERVER\. Now we have to archive the data from one database server to other database server.   Let us suppose the database server \SOURCE_DATABASE_SERVER\ is the live production database server and \DESTINATION_DATABASE_SERVER\ is Long term storage database server. Now data from \SOURCE_DATABASE_SERVER\ needs to be archived into the database server \DESTINATION_DATABASE_SERVER\.   So I have written a dynamic stored procedure which includes distributed transaction (begin Tran, commit Tran, rollback            Tran) coding in it.   Now initially when I executed the procedure, it gave some of the following errors   1) OLE DB provider "SQLNCLI" for linked server "\DESTINATION_DATABASE_SERVER\" returned message "The partner transaction manager has disabled its support for remote/network transactions.". Msg 7391, Level 16, State 2, Line 1 The operation could not be performed because OLE DB provider "SQLNCLI" for linked server "\DESTINATION_DATABASE_SERVER\" was unable to begin a distributed transaction.    

Single-page restore/recover in an online database

I am working with SQL Server 2008 64-bit (10.0.2531) on Windows Server Datacenter 2008 SP2 (64-bit). The problems I am having almost certainly stem from my lack of understanding of how SQL Server's transaction log is handled during recoveries. I am using this document as a rough guide. Here' what I am doing: 1. I intentionally corrupt a single data page in a normal table, so that I can practice single-page recovery. 2. I attempt to read the corrupt block in SQL. As expected I receive an error. 1> select top 10 firstname from ds2.dbo.customers 2> go Msg 824, Level 24, State 2, Server IP-0AF647E0, Line 1 SQL Server detected a logical consistency-based I/O error: incorrect pageid (expected 4:896; actual 3:0). It occurred during a read of page (4:896) in database ID 5 at offset 0x00000000700000 in file 'C:\sql\dbfiles\cust1.ndf'. Additional messages in the SQL Server error log or system event log may provide more detail. 3. I take a log tail backup before I do anything to try to fix the corruption: 1> backup log ds2 to disk = 'c:\sqlbackup\ds2.bak' with norecovery 2> go Processed 5 pages for database 'ds2', file 'ds_log' on file 1. BACKUP LOG successfully processed 5 pages in 0.041 seconds (0.857 MB/sec). 4. I  restore the corrupt page from backup: 1> restore database ds2 page='4:896' 2> from disk='c:\sqlbackup\ds2.bak' 3> with norecovery 4&

My Sql server 2005 Database in recovery mode for 3 -4 hours every day

Hi , Some of our Sql Server 2005 databases remain in recovery mode after midnight for almost 3 to 4 hours. So when my application access them error "Databse in recovery" and for same database this happens again and again every night. Please suggest why and how this can be solved?

SharePoint 2010 Server: Cannot manage all user profiles from upgraded MOSS SSP database

I have upgraded an SSP database to SharePoint 2010 and successfully performed User Profile Synchronization with Active Directory, however I cannot manage ALL of the user profiles in the database. I go to "Manage User Profiles" in Central Administration and perform a filtered search (i.e. I want all DOMAIN accounts beginning with "j" so I search for "DOMAIN\j" in Manage User Profiles), but I don't receive ALL the user profiles back. I receive about 8 in return when I know there are about 20 starting with "j". If I create a new AD account beginning with "j" it is successfully synched with SharePoint 2010 and I see it in the Manage User Profiles. I ran an stsadm -o sync to clear any old synchronization information, and the Forefront Synchronization Service appeared to pull in many changes to existing accounts (including ones I can't currently manage), but I still cannot manage them using "Manage User Profiles". I really need to be able to manage all the profiles so I can manually edit some fields. Can anyone please help? Thanks in advance.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend