How to close the existing connections to a particluar database in sql server. Please note that i donot want to start stop sql server. I just want to close the existing connections so that i can do a restore on that database programatically.
I am using sqldmo for this purpose. Does anyone knows how to do that with sqldmo or is there any other method??
We're using a backup with sql server agent when doing a backup / restore procedure. In some cases I get the following error when the restore job fails:
Executed as user: DOMAINAdministrator. Exclusive access could not be obtained because the database is in use. [SQLSTATE 42000] (Error 3101) RESTORE DATABASE is terminating abnormally. [SQLSTATE 42000] (Error 3013). The step failed.
Is it related to unhandled lock? I've resolved this by restarting the sql server. But is there a way to avoid such issues? One more question. Is it OK to backup/restore database while there're users connected? Or I can do only backup?
I did a full BACKUP for two SQL databases using SQL Server Managament Studio. When trying to RESTORE the DBs, I get the following error:
"System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use. (Microsoft.SqlServer.Smo)"
There are NO users using the application. These are DBs for the Portfolio Server 2007 application.
After exploring a little bit, I found that there are several "SLEEPING" processes with an "AWATING COMMAND" flag. The processes come from the Portfolio Server Application, maybe from previous sessions.
Can they be deleted? if so, would there be any serious consequences?
Hi all. I have read and implemented the very helpful threads on backing up and restoring with user instance posted with MFriedlander. Thank you. However, during the rs.SqlRestore(srv) command I am getting the following error "Restore failed for Server '\.pipe4A1F91FF-F6FE-45 sqlquery'. " "Exclusive access could not be obtained because the database is in use."
I have implemented the changedatabase method as described in that thread.
right before the line
I do not use the default instance of sql express, but I do use an instance called 'test' for my app. Should my changedatabase method also refer to my sql instance?
I am running from VS 2005 debug (F5) when it fails and cannot think of anything that would be locking it. Any help would be appreciated. Thank you. Below is the full code of the restore.
Dim sqlconnection As SqlConnection = New SqlConnection(My.Settings.dbTestConnectionString)
Dim ServerConnection As ServerConnection = New ServerConnection(sqlconnection)
Dim srv As Server = New Server(ServerConnection)
'Declare a BackupDeviceItem by supplying the backup device file name in the constructor, and the type of device is a file.
Dim bdi As BackupDeviceItem
bdi = New BackupDeviceItem(txtRestoreFile.Text, DeviceType.File)
''Define a Restore object variable.
Dim rs As New Restore
'Set the NoRecovery property to true, so the transactions are not recovered.
rs.NoRecovery = True
rs.ReplaceDatabase = True
'Add the device that contains the full database backup to the Restore object.
'don't know why the below norecovery is changed to false
rs.NoRecovery = False
'Specify the database name.
rs.Database = sqlconnection.Database.ToString()
'Restore the full database backup with no recovery.
My question is regarding SQL Server database security. I want to create a login using SQL Server Authentication and assign it db_owner rights for my database. So far so good. But the critical part is that I want to give exclusive rights for my database to this user only i.e. no other users (dbo, guest etc) should be allowed to access my database.
It will be good to present here the scenario which I need to implement. I am running an ASP.NET application that uses SQL server 2005 db at back end. The database server might have other databases as well but I don't want the administrator (either SQL server admin or the server administrator) to be able to get access to my database or even view the schema. I don't want any other user except my own user to be able to detach the database or perform backup or restore operations.
RESTORE DATABASE HIWDYNARPT FROM PRDBACKUP WITH REPLACE __________________________________________________ ______
This works when I test it during the day, however when it runs at night I get the following error in the job log:
Database in use. The system administrator must have exclusive use of the database to run the restore operation. [SQLSTATE 42000] (Error 3101) Backup or restore operation terminating abnormally. [SQLSTATE 42000] (Error 3013). The step failed.
I'm not sure why this happens because I have killed all open threads in step 1, and then create my own new thread in step two. Maybe someone else is initiating a new thread to quickly between the steps???
Anyway, I am trying to use: __________________________________________________ __ ALTER DATABASE HIWDYNARPT RESTRICTED_USER WITH ROLLBACK IMMEDIATE __________________________________________________ ____
...as an alternative to the T-SQL killing PID's, but SQL 7.0 SP4 does not seem to support restricted user like 2000. It keeps giving me a syntax error. Does anyone have any suggestions?
If I bring step 1 and step 2 together, separated by "GO", could this fix the problem?
Purpose I would like to know if it is possible and if so how to implement exclusive access to a given record within in a database table.
Example For example, you can open a file system file with exclusive access so other processes cannot access the file until it is released. I would like to implement a solution that provides this same exclusive access at the database record level. Preferably a solution that does not require creating and managing table access state flags. (i.e. €“ FieldName.State = (Closed, Opened, Exclusive)) I would like for the database server to mange this solution and return an error status when trying to access a record that has been opened exclusively. Furthermore, I would like to avoid using triggers.
Application Utilization I€™m working on a system that has multiple threads that are each responsible managing data from the same normalized table. Each of these system threads work on the same unique record in parallel. Therefore it is possible that thread (0)€™s changes could be overwritten by thread (n)€™s. I would like to have each thread open the unique record exclusively and release it when finished. All of the other threads would loop until the record is released.
1. Is it possible to implement this at the server level?
2. What would be the easiest best practice for implementing this functional requirement?
Hi I've backed up my database... When i try to load it it's telling me that: DBLIB error message: "General SQL Server error: Check messages from the SQL Server.". Server error message: "Database in use. System Administrator must have exclusive use of database to run load.". Can someone tell me how to work around this problem... I have put dbo use only for that database in EM..But i still get the same error...
i have stupid problem that had effect my application distripuotion which i think is related either to connection string or something of the security setting of sql server or iis , actually i do not know what to do: the details of the problem is a have multi connection strings in this form : sqlconnectionPubs = New Data.SqlClient.SqlConnection("Server=SALES-SERVER;Database=NajdiaServiceRequestDta; Asynchronous Processing=true; Integrated Security=True; Trusted_Connection=Yes;") and the connection works just fine in my computer , even i put the database in the main server and still i can post data from my pc to the main server where my database exist but when i try to post from any other computer in the network it tells me : run time error : computer name could not be obtained. I appreciat any help thanks,
We have been asked to look into using stored procedures with SQL Server 7.0 as a way to speed up a clients site. 99% of all the articles I have read along with all the books all say Stored Procedure should be used whenever possible as opposed to putting the SQL in your ASP script. However one of my colleagues has been speaking to Microsoft and they said that that they were surprised that our client wanted to use Stored Procedures as this was the old method of database access and that now he should really consider using COM objects for data access as itis much faster. Has anyone got any views on this or know of any good aticles regarding this matter ?
A problem about many to many relationships from an SQL beginner. Here's a contrived abstract example, as I'd prefer not to give away specifics.
Imagine I have two tables: users, food The relationship (to like) is many-to-many so I've got a link table, which might look like the below:
andrew, apples bob, banana bob, apples chris, carrots chris, apples chris, banana
I want to select users who like bananas and apples exclusively.
The answer should be 'bob' ONLY. select * from users inner join food on <IDs> where food in ('bananas','apples') isn't suitable , because it'll also return 'chris' who should be disqualified (because he also likes carrots).
Apart from potentially being bad DB design (although this is an abstract example; I do have ID numbers), can anyone suggest how to get this in a scalable way?
I have a spid that belongs to the SQLAgent that has my master db and log tied up with exclusive locks. The process it was running has hung. How do I unlock the db and log without killing this spid. I have replication running and it relies on SQLAgent. Help!!
Anybody know how a SELECT statement can generate an exclusive lock on a table ? I always thought that SELECT's take out shared locks. Is this something to do with temporary tables generated by ORDER BY's and DISTINCT ? Rogue SQL below (from Site Server).
SELECT A.i_Dsid, A.i_Aid, A.vc_Val, A.i_Val, A.dt_Val, A.img_Val FROM Object_Attributes A, ( SELECT DISTINCT L.i_Dsid FROM Object_Lookup L , Object_Attributes OA2 (index = IND_vc_Aid) WHERE ((( L.i_ObjectClass = 9999 )) AND ( OA2.vc_Val LIKE ( '999999999.9999999%' ) AND OA2.i_Aid = 99)) AND (L.i_Container_Dsid = 99) AND ( OA2.i_Dsid = L.i_Dsid )) AS B WHERE B.i_Dsid = A.i_Dsid AND A.i_Aid NOT IN( 1, 2, 3, 4, 5 ) ORDER BY A.i_Dsid, A.i_Aid
Hello All! I want to perform 4 or 5 statements as a transaction but I need to make sure that during this complete transaction no one else inserts or deletes records from a table named SomeTable. So how can I lock MyTable at the beggining of the transaction so that during my transaction no one else can insert or delete anything in table SomeTable? Thanks! David
I'm relatively new to SQL and I've come across something that doesn't seem quite right. When an insert becomes part of an transaction I notice an exclusive KEY lock in Enterprise Manager. The table in question was using a Clustered index but I changed that, dropped the table and brought it back in but I still get the lock which keeps all others out of the table. Is this the expected behavior or is there something I am missing? Could the size of the tabe affect things? This is a very small table currently. I'm using MSSQL 7 sp3.
HI, i am trying to make query that has computations with it. but when there's a point computing between int and float i had to use cast() function to convert certain data types. somehow it only works on converting float to integer because when i'm converting an integer into float inorder to be computed with a float it bombs. my query is like this ....
SELECT cast(((cast(((lat - (SELECT LAT FROM TPS_ZIPUSA WHERE ZIP_CODE = 00210)) * 69.1) AS int) ^ 2) + (cast((69.1 * (lng - (SELECT Lng FROM TPS_ZIPUSA WHERE ZIP_CODE = 00210)) * (COS((SELECT LAT FROM TPS_ZIPUSA WHERE ZIP_CODE = 00210) / 57.3))) AS int) ^ 2)) AS float) ^ .5 FROM TPS_ZIPUSA
.5 is where the query bombs. any idea why is this happenning?
Hi , I have some issues with deadlock.I am getting deadlock becuase of two select on same table. The sql server log is like this , Select statements should have always shared lock.I am not getting why its doing exclusive lock and creating deadlock.
5/6/2008 12:38 spid4s Unknown Deadlock encountered €¦. Printing deadlock information 5/6/2008 12:38 spid4s Unknown Wait-for graph 5/6/2008 12:38 spid4s Unknown Log Viewer could not read information for this log entry. Cause: Data is Null. This method or property cannot be called on Null values.. Content: 5/6/2008 12:38 spid4s Unknown Node:1 5/6/2008 12:38 spid4s Unknown KEY: 9:72057594050117632 (8d036f07c58f) CleanCnt:3 Mode Flags: 0Ã—0 5/6/2008 12:38 spid4s Unknown Grant List 3: 5/6/2008 12:38 spid4s Unknown Owner:0Ã—12E9F160 Mode: S Flg:0Ã—0 Ref:1 Life:00000001 SPID:68 ECID:0 XactLockInfo: 0Ã—353D1C54 5/6/2008 12:38 spid4s Unknown SPID: 68 ECID: 0 Statement Type: SELECT Line #: 4 5/6/2008 12:38 spid4s Unknown Input Buf: Language Event: (@actDefId nvarchar(36)@stateList varchar(1)@stateList1 varchar(1)@procRelObjType smallint@procRelObjIdList varchar(36)) 5/6/2008 12:38 spid4s Unknown Requested By: 5/6/2008 12:38 spid4s Unknown ResType:LockOwner Stype:€™OR€™Xdes: 0Ã—2FBB67F0 Mode: X SPID:112 BatchID:0 ECID:0 TaskProxy0Ã—0792E378) Value:0Ã—38baa20 Cost0/11888) 5/6/2008 12:38 spid4s Unknown Log Viewer could not read information for this log entry. Cause: Data is Null. This method or property cannot be called on Null values.. Content: 5/6/2008 12:38 spid4s Unknown Node:2 5/6/2008 12:38 spid4s Unknown KEY: 9:72057594049986560 (6f02e1cd37c3) CleanCnt:3 Mode:X Flags: 0Ã—0 5/6/2008 12:38 spid4s Unknown Wait List: 5/6/2008 12:38 spid4s Unknown Owner:0Ã—12396EE0 Mode: S Flg:0Ã—2 Ref:1 Life:00000000 SPID:90 ECID:0 XactLockInfo: 0Ã—0AA8178C 5/6/2008 12:38 spid4s Unknown SPID: 90 ECID: 0 Statement Type: SELECT Line #: 4 5/6/2008 12:38 spid4s Unknown Input Buf: Language Event: (@actDefId nvarchar(36)@stateList varchar(1)@stateList1 varchar(1)@procRelObjType smallint@procRelObjIdList varchar(36)) 5/6/2008 12:38 spid4s Unknown Requested By: 5/6/2008 12:38 spid4s Unknown ResType:LockOwner Stype:€™OR€™Xdes: 0Ã—353D1C30 Mode: S SPID:68 BatchID:0 ECID:0 TaskProxy0Ã—13B3E378) Value:0Ã—12e9e780 Cost0/6164) 5/6/2008 12:38 spid4s Unknown Log Viewer could not read information for this log entry. Cause: Data is Null. This method or property cannot be called on Null values.. Content:
If you have any idea regarding this please let me know ASAP.