PDA

View Full Version : Create Database, Attach Database Whatever works



Rahvyn
04-13-2007, 12:25 PM
Ok,
:eek:
This should be a fairly simple task I would think. SQL Express gets installed. Next step is to create a database, either using a sql script or by attaching an already existing database. Either way, you would think File.Run using sqlcmd would do the trick. But for the life of me, I cannot figure out how to get this to work. If anyone has done this and has an example, or a tried and true method to get this done, would you please share it.

Thanks

Rahvyn
04-13-2007, 02:18 PM
Let me expand on that a bit. I use the following command in the "On Post Install" section:

File.Run("sqlcmd", " -S .\\SQLEXPRESS -U sa -P sql -o C:\sqlout.txt -i "..strLoc.."\\BatchFieldLayout.sql", "", SW_HIDE, true);

I have about 15 of those, all the same except for the file. The first time I run the install, it installs SQL Express just fine, but errors on the File.Run commands with error 1013 - File Execution Failed. However, if I run the install again right after that, it will skip the SQL Express setup, but the commands execute just fine. SQL Express is installed with the following command line:

File.Run(strTempFolder.."\\MSSQLSERVER\\SQLEXPR.exe", " /qb ADDLOCAL=ALL AGTAUTOSTART=1 DISABLENETWORKPROTOCOLS=0 USERNAME=Smartlinc COMPANYNAME=Smartlinc SECURITYMODE=SQL SAPWD=sql", "", SW_SHOWNORMAL, true);

I have checked after the SQL Express install, but before continuing on with the rest of the install, and all the services are running correctly for SQL Express. I'm at a loss as to why this would happen. Has anyone run into this before?

Jason Pate
04-13-2007, 02:40 PM
First thing I noticed is that C:\ is missing the double "\\" so that will cause you a problem. Also might try putting in a working directory, and also giving the full path to sqlcmd might help.


File.Run("sqlcmd", " -S .\\SQLEXPRESS -U sa -P sql -o C:\sqlout.txt -i "..strLoc.."\\BatchFieldLayout.sql", "", SW_HIDE, true);


File.Run("sqlcmd", " -S .\\SQLEXPRESS -U sa -P sql -o C:\\sqlout.txt -i "..strLoc.."\\BatchFieldLayout.sql", "", SW_HIDE, true);


C:\\

Rahvyn
04-14-2007, 05:43 PM
Didnt notice the \\, will try the full path, and what exactly will a working directory do? The thing that bothers me most is that if I run the install again the commands execute just fine.

Jason Pate
04-16-2007, 01:16 PM
Working directory is like the old DOS path command, it gives the program a location to look for its base files, and required sub files, its not always needed, but if your having isses (As I had just a few weeks ago) making that adjustment might just work.

Rahvyn
04-16-2007, 03:14 PM
Got it working, put the full path to the sqlcmd in there and that did it. Thanks for the help Jason.