1

I ran into real brick wall trying to connect to dynamic databases. And I don't know how to achieve this,

Here is my process, I have an application where it needs to be adaptable to changes in the work environment, say If the work places server crashes and they create a new database with the name db_new the application would connect to that instead of the old database name.

I already have a window that displays the databases from the server on a listbox where the user can specify which database to use for the application. But the issue is, how can I save the selected database name so that it can run after the new database is selected? ..

as in the administrator should be able to change the database the application uses if necessary and the application should keep on using that selected database till the administrator changes it back to a new one.

Please forgive if the question a bit vague, I just put it together in the best way I could, any help on this would be really great :)

EDIT:

And I cannot use text files or xml s as the database name the application uses should be stored in a secure manner. :)

Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164
Hasitha Shan
  • 2,900
  • 6
  • 42
  • 83
  • How do you display the databases list? post the code you are using. – Mahmoud Gamal Sep 16 '12 at 12:12
  • using the "show databases" query :) – Hasitha Shan Sep 16 '12 at 12:14
  • 1
    Then you should be able to get its name using `row["database_name"]` then save its value in the web.config file for exmaple – Mahmoud Gamal Sep 16 '12 at 12:17
  • so, if i save it in the web.config file, will it be secure enough?:) if this is possible that would be great. But i am developing desktop application so, is it possible with desktop applications, if there is no alternative i can turn to web :) – Hasitha Shan Sep 16 '12 at 12:22
  • Sorry for the descktop applications use the App.config file instead of the web.config. And yes it would be accessible from within your application after the program is closed. But the problem is that it wouldn't be secured since the Administrator may hack this file. – Mahmoud Gamal Sep 16 '12 at 12:27
  • oh..okey..thank you for your input..:) you gave me a place to start out with.. :) – Hasitha Shan Sep 16 '12 at 12:30

2 Answers2

1

First of all, you can very easily use a text or XML file: If you store the information in a file, that can't be downloaded by the user (as I assume you would), this is as safe as it can be: If somebody manages to break into the server and read the file, it's game over anyway.

That said, I would recommend you use MySQL proxy or a similar mechanism and point your WebApp at it - failing over to another database or changing the underlying database could then be handled at the proxy layer without the WebApp even knowing about it: The functionality need not be part of your application and in my book it shouldn't.

Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
  • okey :).. this gave me alot to think about.. I will research on the mysql proxy .. can you point me in a direction where i could use this feature.. because this mysql proxy is completely new to me an willing to learn about it..:) – Hasitha Shan Sep 16 '12 at 12:43
  • MySQL proxy is quite easy: Start at http://dev.mysql.com/doc/refman/5.5/en/mysql-proxy.html. You can also look at SQLrelay http://sqlrelay.sourceforge.net/ – Eugen Rieck Sep 16 '12 at 12:58
0

You haven't told us the language you are using. Therefore we cannot offer very good suggestions.

My first thoughts:

If this was PHP you could have the general app use something along the lines of,

$db->execute('sql statement here');

and then just have the administrator change the current $db when needed. That way $db->execute() will always be executed on the "current" database.

Edit: This should still work in C#. If you have the functions using the database call a variable that is the current db connection then you should be able to change the db connection to the proper database whenever you need while the rest of it continues running since it's just the same variable.

BSull
  • 329
  • 2
  • 10