Friday, February 24, 2012

Installing SQL express and attaching a mdf db from the Command Prompt

Hi,

I need to install a customed SQL server express instance on the client's computer by using the Command prompt installation. I've already defined the security settings and everything i need but i was wondering if is possible to attach a mdf database during the installation. Perhaps there is a paramenter i can include in the in the ini file.

Thank you

No, you can not attach a database as part of the installation command prompt. You will need to do that from some other process, possibly in the wrapper that you're using to run the command prompt in the first place. If you're not using a language that supports connecting to SQL, you could just create a script and call that script using the SQLCmd utility, which runs from the command prompt as well.

Search BOL for information about using SQLCmd.

Mike

|||Hi,

if you embedded your installation as part of a bootstrapper you could call (as Mike said) the SQLCmd.exe utiltiy as a custom install step and use the sp_attachdb or CREATE DATABSE for attaching within the command like the following example: SQLCMD.exe -E -Q"sp_attach @.dbname ='SomeDbname', @.FileName1 ='C:\SomeFOlder\SomeFile.mdf', @.FileName2 ='C:\SomeFOlder\SomeFile.mdf'

Jens K. Suessmeyer.

http://www.sqlserver2005.de
|||

Thank you for your answers.

Just one last thing: I creating two separate procedures to install and attach the database into one wrapper. Because launching a SqlCmd starts a separate sql installation. Is there a way to know when the installation is completed and how it went so the attachment process can be launched automatically?

|||

When I do the script you mention it works for some computers and for others it won't.

I found that changing the SQL Server Configuration manager(SCM) to local for those that it doesn't work is enough to make the script run. When it was setup as NTAuthority instead of local it gave a Error 5 (acces denied).

Is any command to change the Logon Mode for the SCM that I can add as part of my script?
What am I doing wrong? How to default it to be a local logon instead of NTAuthority?

No comments:

Post a Comment