Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

How to Deploy the database to Xampp Server ?

$
0
0

I am using the below-written script to upload my database to the XAMPP server automatically when I install my exe file but unfortunately, it's not happening. I am placing my ".SQL" file in the same folder where my exe file is located manually and I am using click once a method to make exe file. Kindly check the below code and guide me accordingly where I am wrong

   public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
       
        public  void MainWindow_load(object sender,EventArgs e)
        {
            if (!checkifdbexist())
            {
                generatedatabase();
            }
        }
        private bool checkifdbexist()
        {
            String conn = "datasource=127.0.0.1;port=3306;username=root;password=;Initial Catalog=Demon;";
            MySqlConnection con = new MySqlConnection(conn);
            try
            {
                con.Open();
                return true;
            }
            catch
            {
                return false;
               
            }
           


        }

        private void generatedatabase()
        {
            List<string> cmds = new List<string>();
            if (File.Exists(System.Windows.Forms.Application.StartupPath + "\\demo.sql"))
            {
                TextReader tr = new StreamReader(System.Windows.Forms.Application.StartupPath + "\\demo.sql");
                String line = "";
                string cmd = "";
                while ((line = tr.ReadLine()) != null)
                {
                    if (line.Trim().ToUpper() == "GO")
                    {

                        cmds.Add(cmd);
                        cmd = "";
                    }
                    else
                    {
                        cmd += line + "\r\n";
                        System.Windows.MessageBox.Show(" No file");

                    }
                }
                if (cmd.Length > 0)
                {
                    cmds.Add(cmd);
                    cmd = "";

                }
                tr.Close();

            }
            if (cmds.Count > 0)
            {
                MySqlCommand comm = new MySqlCommand();
                comm.Connection = new MySqlConnection("datasource=127.0.0.1;port=3306;username=root;password=;Initial Catalog=MASTER;");
                comm.CommandType = System.Data.CommandType.Text;
                comm.Connection.Open();
                for (int i = 0; i < cmds.Count; i++)
                {
                    comm.CommandText = cmds[i];
                    comm.ExecuteNonQuery();
                   
                }
            }
     



        }




Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>