Check if SQL Database Already Exists
I'm using Wise Installation Studio to install an application that uses a SQL Server database. I'd like the user to be able to create the database during the install or select an existing database to use if the database already exists. I modified the Database Dialog by adding a textbox for the database name. With that, I have been able to pass the information to a SQL script and successfully create a new database.
Problem:
If the user enters a database name, and it already exists on the server, the SQL scripts that run duing the installation return numerous errors. It would be really helpful to be able to handle it in the Database Dialog, but I'm not sure how to do it.
Questions:
1. If the user wants to install a new database and a database with the same named already exists on the server, how can I return a message to them that the database already exists and they need to enter a different name for the database they are going to create?
2. Is there a way I can check if a database exists when the "next" button is clicked on the database dialog?
3. Should a custom action be used?
4. Are there any examples of custom actions or scripts that can do it?
Thanks
Comments
My first thought was...
...to create a CA to interrogate the SQL Server in question. IIRC, SQL Server has a WMI interface which you can use. Don't quote me, though...
Don't know why 'x' happened? Want to know why 'y' happened? Use ProcMon and it will tell you.
Think about using http://www.google.com before posting.
What sort of custom action
What sort of custom action would be best for that purpose (Call VBScript From Installation, etc.)? Should the custom action run a vbscript to do it and return the output to a property?
That would be my gambit, yes.
That would be my gambit, yes, if only because you'll find many, many examples of SQL scripts in VBS. If you Google for 'SQL Server WMI', you'll see what I mean.
Don't know why 'x' happened? Want to know why 'y' happened? Use ProcMon and it will tell you.
Think about using http://www.google.com before posting.
Please clarify a few points
Is your application being installed on an SQL server system, or are you installing on a user workstation and intending to create/access an SQL database on a network connected server?
If it is the latter, will the installation always be manual, and using a domain account with the appropriate admin privileges both on the local workstation and on the server?
If your issue has been solved, please use the "Mark as Solution" link on the most relevant thread.
The application is going to
The application is going to be a website that uses a SQL Server database. During the installation, I'm using the database dialog to specifiy the server, database name, username and password. With these items, I can create a connection string for the web.config of the application and also do some replacements in two sql scripts that are run in the install (one to create the db and another to create tables and strored procedures). I'd like to check if the database exists on the server before I run the scripts and show a message to the user that the database exists and cancel the install or force them to enter a different DB name.
Somebody will always manually click the msi to install the application. They should have admin privileges.
Thanks
So you're installing to the SQL server?
So you're installing to the SQL server?
If your issue has been solved, please use the "Mark as Solution" link on the most relevant thread.
Update
To check if the database exists, in the Setup Editor, I chose the Tables tab. The I clicked on the Binary tab and added a new row to the table with the title of a vbscript as the name. Then I click on the CustomAction item and added a new row, gave the custom action a name and type, set the source to the title of my vbscript and entered a name for the target.
After that I went to the SQL Connection dialog and added a DoAction event to the Next button that calls the CustomAction containing the vbscript. To pass information to and from Wise to the vbscript the syntax of the property is 'session.property("PROPERTY NAME HERE"). When the vbscript is called it checks for a database on the server and sets a property that is used as the event's condition. The condition can then be used to allow or prevent the installation from continuing.
Thanks to everybody for the help.
Would you like to reply?
Login or Register to post your comment.