Attach and detach MSDE databases

To detach a database directly from the command prompt:

osql -U sa -P MyPassword -S MSDEInstance -Q "sp_detach_db 'databasename'"

To detach a database from within MSDE:

osql -U sa -P MyPassword -S MSDEInstance
1> exec sp_detach_db 'databasename'
2> go

To attach a database directly from the command prompt:

osql -U sa -P MyPassword -S MSDEInstance -Q "sp_attach_db 'dbname', '$DBPATH\dbname.mdf', '$LOGPATH\dbname_log.LDF'"

To attach a database from within MSDE:

osql -U sa -P MyPassword -S MSDEInstance
1> exec sp_attach_db 'dbname', '$DBPATH\dbname.mdf', '$LOGPATH\dbanme_log.LDF'
2> go

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: