Three ways to check successful install
I want to include Sql Express in my own application. I have looked at the MSDN article about this (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsse/html/EmSQLExCustApp.asp) - great article BTW. But one thing is missing, namely, how to programmatically detect if Sql Express was installed successfully or not?
I know I could parse the summary.txt log file found inC:\Program Files\Microsoft SQL Server\90\Setup Bootstrap\LOG - but that really sucks in my opinion.Is there a good and solid way to do this check?
Thanks,
Henrik Bach
Hello,
Three things come to mind, and all are pretty easy.
First, if SQL Server express is successfully installed, I would expect an instance of it to be running. So, perhaps you could enumerate services and look for service MSSQLSERVER sqlservr.exe (watch the spelling!) with a status of running.
Or, why not just run your program and try to connect to it. If SQL Server is not running or not present, you'll get a dandy error message returned to you in code.
Lastly, just issue a NET START MSSQLSERVER from code. If the service is running, it will say so. If not, it will start it. If there is no such service, it will tell you that too.
Perhaps you can redirect the command line output to a file and then read the file. If you execute this command, the result is put into file c:\running.txt
cmd /k sc query mssqlserver >c:\running.txt
NOTE: Depending on the version of SQL Server you have, you may have to change the name of the service. The display name of the service is not necessarily the service name.
After a successful install, right click My Computer, select Manage, then expand Services in the left pane. Find the instance of SQL Server in the list in the right pane. Right-click it and select Properties to see the actual service name.
For example, for my copy of SQL Server 2005 Express, instead of MSSQLSERVER in the above examples, I have to use MSSQL$SQLEXPRESS
i.e.
NET START MSSQL$SQLEXPRESS
or
cmd /k sc query MSSQL$SQLEXPRESS >c:\running.txt
SQL Wizard