I have the following code:
Set oServer = New SQLDMO.SQLServer
oServer.Connect (Servername), ServerID, ServerPwd
Call oServer.DetachDB(DBName, True)
oServer.Close
however, I continue getting the following error:
"Cannot detach the database 'Northwind' because it is currently in use"
Doing a detach with Enterprise manager works just fine on the same
server/db - - it's just that, with coding it, I get the error - -
what might I be doing wrong?hi,
Appears that there is a connection string live with the Northwind database
when you are dettaching the Northwind DB. Verify the same by putting a
breakpoint just before oServer.DetachDB(DBName, True) and then connect to
master DB from queryanalyzer and fire sp_who.
Ideally while using DMO you should connect explicitly to master db and then
try to dettach any other db.
Let us know if it solves ur issue...
cheers,
siaj
"Elmo Watson" wrote:
> I have the following code:
> Set oServer = New SQLDMO.SQLServer
> oServer.Connect (Servername), ServerID, ServerPwd
> Call oServer.DetachDB(DBName, True)
> oServer.Close
> however, I continue getting the following error:
> "Cannot detach the database 'Northwind' because it is currently in use"
> Doing a detach with Enterprise manager works just fine on the same
> server/db - - it's just that, with coding it, I get the error - -
> what might I be doing wrong?
>
>|||I see 16 entries when I do what you ask - most say background or
sleeping - - one says runnable - - I'm afraid I really don't know what this
gives me...
how can I close all connections before doing this?
"siaj" <siaj@.discussions.microsoft.com> wrote in message
news:6185D09E-6052-4CA8-8AE1-60EBE323149B@.microsoft.com...
> hi,
> Appears that there is a connection string live with the Northwind database
> when you are dettaching the Northwind DB. Verify the same by putting a
> breakpoint just before oServer.DetachDB(DBName, True) and then connect to
> master DB from queryanalyzer and fire sp_who.
> Ideally while using DMO you should connect explicitly to master db and
then
> try to dettach any other db.
> Let us know if it solves ur issue...
> cheers,
> siaj
>
> "Elmo Watson" wrote:
>|||Hi,
1.How many process show as the DBname as Northwind ... ideally they should
be none.
2. Which is the default database in ur SQL server. Verify that it should be
master in ur case. If not u can set it through sp_defaultDB in QA
3. While connecting through SQL-DMO make sure no users are connected to the
said DB(including urself/ QA)
4.In oServer.Connect (Servername), ServerID, ServerPwd also specify the
dbname property as "master"
5. Verify now thru sp_who how many connections are there to Northwind
..ideally there should be none.
6. Now try to dettach the DB
Let us know if u have any success...
cheers,
siaj
Which is your default database in the SQL Server....
"Elmo Watson" wrote:
> I see 16 entries when I do what you ask - most say background or
> sleeping - - one says runnable - - I'm afraid I really don't know what thi
s
> gives me...
> how can I close all connections before doing this?
>
>
> "siaj" <siaj@.discussions.microsoft.com> wrote in message
> news:6185D09E-6052-4CA8-8AE1-60EBE323149B@.microsoft.com...
> then
>
>|||Only one connection shows as Northwind - its host is the computer name - -
However, this can happen when I reboot and start fresh - that's the way it
comes up - I haven't run any program I know that hits the database.
I added a line :
oDataBase=oServer("master") - to make sure it hits the master when it
connects...
I also changed the default database to master
No matter what - it seems like there is always a connection to the Northwind
database (or any others also, for that server - - )
I just don't understand how this is happening and how to get around it...
"siaj" <siaj@.discussions.microsoft.com> wrote in message
news:34D5FCE9-C469-4B7A-AFA7-E9731EECF209@.microsoft.com...
> Hi,
> 1.How many process show as the DBname as Northwind ... ideally they
should
> be none.
> 2. Which is the default database in ur SQL server. Verify that it should
be
> master in ur case. If not u can set it through sp_defaultDB in QA
> 3. While connecting through SQL-DMO make sure no users are connected to
the
> said DB(including urself/ QA)
> 4.In oServer.Connect (Servername), ServerID, ServerPwd also specify the
> dbname property as "master"
> 5. Verify now thru sp_who how many connections are there to Northwind
> ..ideally there should be none.
> 6. Now try to dettach the DB
> Let us know if u have any success...
> cheers,
> siaj
>
> Which is your default database in the SQL Server....
> "Elmo Watson" wrote:
>
this
database
to
use"|||Use Profiler to know which application is opening a connection to the
Northwind Database.
siaj
"Elmo Watson" wrote:
> Only one connection shows as Northwind - its host is the computer name - -
> However, this can happen when I reboot and start fresh - that's the way it
> comes up - I haven't run any program I know that hits the database.
> I added a line :
> oDataBase=oServer("master") - to make sure it hits the master when it
> connects...
> I also changed the default database to master
> No matter what - it seems like there is always a connection to the Northwi
nd
> database (or any others also, for that server - - )
> I just don't understand how this is happening and how to get around it...
>
> "siaj" <siaj@.discussions.microsoft.com> wrote in message
> news:34D5FCE9-C469-4B7A-AFA7-E9731EECF209@.microsoft.com...
> should
> be
> the
> this
> database
> to
> use"
>
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment