TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Abhilash J A
524
2.4k
600.8k
how to check if database exists in MySQL server?
Jan 28 2017 1:43 PM
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);
}
}
}
}
Reply
Answers (
3
)
missing any .dll reference in WPF project
Bind a values from code behind to xaml page