SQL Express connections

pachjo

Well-known member
Joined
Dec 12, 2006
Messages
370
Programming Experience
10+
If an instance of SQL Server Express is created like this:

VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] cnSQLConnection [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SqlClient.SqlConnection = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlClient.SqlConnection([/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.MB2007ConnectionString)
 
cnSQLConnection.Open()
 
[SIZE=2]scnServerConnection = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Microsoft.SqlServer.Management.Common.ServerConnection(cnSQLConnection)
[/SIZE][SIZE=2][COLOR=#008000] 
[/COLOR][/SIZE][SIZE=2]srvAdminServer = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Server(scnServerConnection)
[/SIZE][/SIZE]

Then isn't this classed as an open connection to the database in the connection string?

I am trying to restore a database and before I call the restore code I close the main application connection which allows the user to interact with the database.

But I get an error saying it cannot obtain exclusinve lock on database to restore?

I'm confused then as to how to perform a restore?

Thansk
 
Eventually.....got round to this and the answer is:

MyConnection.Close()

SqlClient.SqlConnection.ClearPool(MyConnection)

Now connect to the database with new connection and restore

When finished re-establish the previous connection to all user to continue using the restored data

:D

Cheers ears ;)
 
Back
Top