|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
close connectioni need to detach a database autoclose property is set to true close cursor on commit is set to true i use the sp_detach with adodb (the program has been converted from vb6) and i receive the error that db is still in use becouse the connection is still actibe i still access to file via adodb in the routine in which i read the db the code is sub readdb dim con as new adodb.connection dim rs as new adodb.connection con.open rs.open... ....read the file rs.close con.close rs = nothing con = nothing end sub at the end of the sub even if i try and retry to detach db the connection reamins active for ever while i expect not (after a while) why? i try to use a sqldatareader and an sqlclient but the problem remains Is there a way to drop connections active via code? thanks best regards DavideR Hi,
Why don't you try to use the smo class to detach the database. Add a reference to microsoft.sqlserver.smo Imports Microsoft.SqlServer.Management.Smo Module Module1 Sub Main() Dim svr As Server = New Server(".\SQLEXPRESS") svr.DetachDatabase("Northwind", True) End Sub End Module Ken ------------------- Show quoteHide quote "DavideR" <Davi***@discussions.microsoft.com> wrote in message news:634945EE-34B8-49E5-8C6E-6F8202EF0B95@microsoft.com... > I'm working with vs2005 (vb.net) > i need to detach a database > autoclose property is set to true > close cursor on commit is set to true > i use the sp_detach with adodb (the program has been converted from vb6) > and i receive the error that db is still in use becouse the connection is > still actibe > i still access to file via adodb > in the routine in which i read the db the code is > sub readdb > dim con as new adodb.connection > dim rs as new adodb.connection > con.open > rs.open... > ...read the file > rs.close > con.close > rs = nothing > con = nothing > end sub > at the end of the sub even if i try and retry to detach db the connection > reamins active for ever while i expect not (after a while) > why? > i try to use a sqldatareader and an sqlclient but the problem remains > Is there a way to drop connections active via code? > thanks > best regards > DavideR > i tried but the problem reamins
how can i drop via the connection??? Show quoteHide quote "Ken Tucker [MVP]" wrote: > Hi, > > Why don't you try to use the smo class to detach the database. > Add a reference to microsoft.sqlserver.smo > > Imports Microsoft.SqlServer.Management.Smo > > Module Module1 > > Sub Main() > Dim svr As Server = New Server(".\SQLEXPRESS") > svr.DetachDatabase("Northwind", True) > > End Sub > > End Module > > > Ken > ------------------- > "DavideR" <Davi***@discussions.microsoft.com> wrote in message > news:634945EE-34B8-49E5-8C6E-6F8202EF0B95@microsoft.com... > > I'm working with vs2005 (vb.net) > > i need to detach a database > > autoclose property is set to true > > close cursor on commit is set to true > > i use the sp_detach with adodb (the program has been converted from vb6) > > and i receive the error that db is still in use becouse the connection is > > still actibe > > i still access to file via adodb > > in the routine in which i read the db the code is > > sub readdb > > dim con as new adodb.connection > > dim rs as new adodb.connection > > con.open > > rs.open... > > ...read the file > > rs.close > > con.close > > rs = nothing > > con = nothing > > end sub > > at the end of the sub even if i try and retry to detach db the connection > > reamins active for ever while i expect not (after a while) > > why? > > i try to use a sqldatareader and an sqlclient but the problem remains > > Is there a way to drop connections active via code? > > thanks > > best regards > > DavideR > > > > > Davide,
A bit late. Use srv.KillAllProcesses() before you detach with SMO. For me it works. Show quoteHide quote "DavideR" wrote: > i tried but the problem reamins > how can i drop via the connection??? > > "Ken Tucker [MVP]" wrote: > > > Hi, > > > > Why don't you try to use the smo class to detach the database. > > Add a reference to microsoft.sqlserver.smo > > > > Imports Microsoft.SqlServer.Management.Smo > > > > Module Module1 > > > > Sub Main() > > Dim svr As Server = New Server(".\SQLEXPRESS") > > svr.DetachDatabase("Northwind", True) > > > > End Sub > > > > End Module > > > > > > Ken > > ------------------- > > "DavideR" <Davi***@discussions.microsoft.com> wrote in message > > news:634945EE-34B8-49E5-8C6E-6F8202EF0B95@microsoft.com... > > > I'm working with vs2005 (vb.net) > > > i need to detach a database > > > autoclose property is set to true > > > close cursor on commit is set to true > > > i use the sp_detach with adodb (the program has been converted from vb6) > > > and i receive the error that db is still in use becouse the connection is > > > still actibe > > > i still access to file via adodb > > > in the routine in which i read the db the code is > > > sub readdb > > > dim con as new adodb.connection > > > dim rs as new adodb.connection > > > con.open > > > rs.open... > > > ...read the file > > > rs.close > > > con.close > > > rs = nothing > > > con = nothing > > > end sub > > > at the end of the sub even if i try and retry to detach db the connection > > > reamins active for ever while i expect not (after a while) > > > why? > > > i try to use a sqldatareader and an sqlclient but the problem remains > > > Is there a way to drop connections active via code? > > > thanks > > > best regards > > > DavideR > > > > > > > > >
Startup a winform hidden
Eval function vb.net Create object through classname How to change "database and User" into CR9 Webservice MyApplication has encountered a problem... when not Administrator! Get IP Address Validating event Access object through String ? How 2 refer to controls by a string variable name instead of index GAC assembly in "Add Reference" dialog box |
|||||||||||||||||||||||