I am about to deploy my application and have came into a bit of trouble.

I have the connection string for the database held in the application.settings and need a way to check if the database exists when the program first starts up, and if it doesn't, i need the program to create it before starting the program.

I am assuming it would be a mysql statement to check if db exists, if not create. However, I don't know where or how to do this, can I create a mysql dump of a blank database with tables etc already created and use that?

I have already stored the mysql dll files locally so there is no problem with that, its just creating the database that the string wants to connect to before the application runs so there are no connection errors straight away.

Thanks.

To check if a database exists, use this select (from here):

SELECT
    SCHEMA_NAME 
FROM
    INFORMATION_SCHEMA.SCHEMATA 
WHERE
    SCHEMA_NAME = 'DBName'

If it doesn't exists, execute the creation script.

Hi, thanks for the reply.

I'm a bit confused about how this will go together. When the user installs my application on thier computer, the mysql dll files are installed with the program. Will the connection be made automatically (i.e. the server info that goes into the connection string, localhost, user etc...).

Also, how will the above select statement run if there is no connection string.

Sorry if these questions sound stupid, I have been working on rhis for hours now and think I have read that much on it I am confusing myself with it.

The target machine will have MySQL arealdy installed?

I was planning on just storing the mysql dll files locally with my program, or would i need to install mysql at the same time as installation of my app?

I'm really not sure if I can help you, proabally not, I've never done something like that myself.

But from what I readed, you could just store the mysql.dll files and it would work. But from my knowlodge, I'd think you would also need to store the mysql database files(because is there that mysql store the tables, records and user information).

Those files are stored in c:\ProgramData\Mysql(in Windows 7). You can verify that in your my.ini, at your MySQL installation folder.

I'd suggest you to setup a virtual machine where you could do those tests.

Sorry I can't help more.

Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.