PDA

View Full Version : SetupBuilder and SQL Express 2005



pNelson
06-16-2010, 09:29 AM
I am trying to package a Windows application written in C#.NET which uses a SQL Express 2005 backend. My setup package checks for .NET Framework, SQL Express 2005 and Windows Installer, and installs the necessary components as needed. I attach to the default SQLEXPRESS database in my application. On my initial install, all works great and my application is able to attach to the database and functions correctly. However, on subsequent installs (uninstall my windows app and then re-install), when I fire up the application, I receive an open error on the database. If I uninstall my app and uninstall SQL Express each time, it works; but if I only uninstall my app, I cannot access the database and receive the open error. Here is my connection string on application start up: stConn = "Data Source=.\\SQLEXPRESS;AttachDbFilename=" + sMyPath + "Mydb.mdf;User Instance=False;Integrated Security=True;password=mypwd;persist security info=True;user id=MyAdmin ";
On application exit, do I need to detach from the the database each time? Or on uninstall, do I need to detach from the database? I am a mezzo newbie and quite frustrated at this point. Any direction would be greatly appreciated.
Kindest Regards.

linder
06-17-2010, 12:27 AM
Hello,

I fear you have to ask your question in a SQL Express 2005 newsgroup (or Microsoft support) because this is a SetupBuilder newsgroup. I can be wrong, but I don't think that you'll receive a good answer here. You'll only find SetupBuilder and/or deployment technique experts here. But your question is for SQL Express 2005 experts.

If you find the answer to this (good) question, please feel free to post it here so others can learn from it.

Friedrich

pNelson
06-17-2010, 08:19 AM
Thanks Friedrich. After I posted my question, I had the same thought. I will post back with the answer if I can.
Kindest Regards.

linder
06-17-2010, 08:57 AM
That would be great. Thank you!

Friedrich

pNelson
06-18-2010, 09:34 AM
After my install, I am trying to attach to my database using the Run Program function in my script, but my application fails with an open database error. On install, when the Run Program function starts and the DOS window pops, I can see the start of a message "Unable to...", but I have not been able to capture this speedy window to see what the full message is. Any way to do that??
Funny thing is I can run my command line from the 'Run' after my installation completes and it is successful, and my application works:
osql -E -S (local)\SQLEXPRESS -Q "CREATE Database MyDatabase ON
(FILENAME=N'C:\Program Files\MyApplication\Database\MyDatabase.mdf'),
(FILENAME=N'C:\Program Files\MyApplication\Database\MyDatabase_log.mdf')
FOR ATTACH"

Here is my Run Program set up:
Run Program:

File Name -or- Web Page Address:
OSQL.exe

Target Folder:
%PROGRAMFILESDIR%\Microsoft SQL Server\90\Tools\Binn

Command Line:
-E -S (local)\SQLEXPRESS -Q "CREATE Database MyDatabase ON
(FILENAME=N'%PROGRAMFILESDIR%\MyApplication\Databa se\MyDatabase.mdf'),
(FILENAME=N'%PROGRAMFILESDIR%\MyApplication\Databa se\MyDatabase_log.mdf')
FOR ATTACH"

options:
Wait for Program
Use ShellExecuteEx

Do you see anything wrong with my syntax that this would not work?
Kindest Regards.

pNelson
06-18-2010, 12:11 PM
Sorry for the multiple posts on this subject, Friedrich. But SUCCESS! After I posted my Run Program setup to you, I noticed that my log file in my command line had a .mdf extension, instead of the .ldf extension. (how many times did I peruse my set up and miss that?!?) Once I corrected the file name, SUCCESS, my Attach via Run Program succeeds!

So the order of business is: Install SQL Express, install my application, attach to my database, run the application.
On application exit, close all connections to my database.
On Uninstall, detach from my database, then uninstall my application.

Kindest Regards.

linder
06-19-2010, 04:22 AM
Wow, perfect. Thanks so much for sharing this very interesting information!!!

Friedrich