Tech
Forums
Jobs
Books
Events
Live
Interviews Prep
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
how to check if database exists in MySQL server?
Mani Kandan
Jan 28 2017 1:43 PM
768
Reply
Hello everyone,
I am using WPF apps with MySQL database. I did create backup.sql file. Then, after create .exe file, how can I check if db exist then skip below code?
private
void
Application_Startup(
object
sender, StartupEventArgs e)
{
RestoreBehavior();
}
private
void
RestoreBehavior()
{
string
constring =
"server=localhost;user=root;pwd=123456;"
;
string
file = @
"C:\Program Files (x86)\xxxx\xxxx\backup.sql"
;
using
(MySqlConnection conn =
new
MySqlConnection(constring))
{
using
(MySqlCommand cmd =
new
MySqlCommand())
{
using
(MySqlBackup mb =
new
MySqlBackup(cmd))
{
cmd.Connection = conn;
conn.Open();
mb.ImportInfo.TargetDatabase =
"mydb"
;/*Here,
How can I check here if mydb exist then skip the code?
*/
mb.ImportInfo.DatabaseDefaultCharSet =
"utf8"
;
mb.ImportFromFile(file);
}
}
}
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
missing any .dll reference in WPF project
Bind a values from code behind to xaml page