Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. setup project to create the database

setup project to create the database

Scheduled Pinned Locked Moved ASP.NET
databasequestioncsharpsql-serversysadmin
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PrakashBhaskar
    wrote on last edited by
    #1

    I am in need to create a setup file for my web application. I can able to create seup file for web application alone but i want to include the installer for creating database (if the sql server is not exist it has to prompt). How do I create the database and then add a table using C# i have a sql script on my hand?

    Thanks Warm Regards Prakash-B

    S L 2 Replies Last reply
    0
    • P PrakashBhaskar

      I am in need to create a setup file for my web application. I can able to create seup file for web application alone but i want to include the installer for creating database (if the sql server is not exist it has to prompt). How do I create the database and then add a table using C# i have a sql script on my hand?

      Thanks Warm Regards Prakash-B

      S Offline
      S Offline
      Sun Rays
      wrote on last edited by
      #2

      Please reply for this..

      Thanks, Sun Rays

      1 Reply Last reply
      0
      • P PrakashBhaskar

        I am in need to create a setup file for my web application. I can able to create seup file for web application alone but i want to include the installer for creating database (if the sql server is not exist it has to prompt). How do I create the database and then add a table using C# i have a sql script on my hand?

        Thanks Warm Regards Prakash-B

        L Offline
        L Offline
        Laxman Auti
        wrote on last edited by
        #3

        PrakashBhaskar wrote:

        I am in need to create a setup file for my web application. I can able to create seup file for web application alone but i want to include the installer for creating database (if the sql server is not exist it has to prompt). How do I create the database and then add a table using C# i have a sql script on my hand?

        Use Regex to parse sql script line by line and use ExecuteNonQuery to execute that line. Knock out 't' from can't, You can if you think you can :cool:

        P 1 Reply Last reply
        0
        • L Laxman Auti

          PrakashBhaskar wrote:

          I am in need to create a setup file for my web application. I can able to create seup file for web application alone but i want to include the installer for creating database (if the sql server is not exist it has to prompt). How do I create the database and then add a table using C# i have a sql script on my hand?

          Use Regex to parse sql script line by line and use ExecuteNonQuery to execute that line. Knock out 't' from can't, You can if you think you can :cool:

          P Offline
          P Offline
          PrakashBhaskar
          wrote on last edited by
          #4

          can you send me the code coz i am new to this deployment project plz.

          Thanks Warm Regards Prakash-B

          L 1 Reply Last reply
          0
          • P PrakashBhaskar

            can you send me the code coz i am new to this deployment project plz.

            Thanks Warm Regards Prakash-B

            L Offline
            L Offline
            Laxman Auti
            wrote on last edited by
            #5

            private static void CreateDBAndTables(SqlConnection sqlCon)
            {
            string[] SqlLine;
            Regex regex = new Regex("^GO", RegexOptions.IgnoreCase | RegexOptions.Multiline);

                    string txtSQL = GetScript("createDB.sql");
                    SqlLine = regex.Split(txtSQL);
                    ExecuteSql(sqlCon, SqlLine);
            

            }

            private static void ExecuteSql(SqlConnection sqlCon, string[] SqlLine)
            {
            SqlCommand cmd = sqlCon.CreateCommand();
            cmd.Connection = sqlCon;

            		foreach(string line in SqlLine)
            		{
            			if(line.Length>0)
            			{
            				cmd.CommandText = line;
            				cmd.CommandType = CommandType.Text;
            				try
            				{
            					cmd.ExecuteNonQuery();
            				}
            				catch(SqlException)
            				{
            					break;
            				}
            			}
            		}
            	}
            

            Knock out 't' from can't, You can if you think you can :cool:

            P 1 Reply Last reply
            0
            • L Laxman Auti

              private static void CreateDBAndTables(SqlConnection sqlCon)
              {
              string[] SqlLine;
              Regex regex = new Regex("^GO", RegexOptions.IgnoreCase | RegexOptions.Multiline);

                      string txtSQL = GetScript("createDB.sql");
                      SqlLine = regex.Split(txtSQL);
                      ExecuteSql(sqlCon, SqlLine);
              

              }

              private static void ExecuteSql(SqlConnection sqlCon, string[] SqlLine)
              {
              SqlCommand cmd = sqlCon.CreateCommand();
              cmd.Connection = sqlCon;

              		foreach(string line in SqlLine)
              		{
              			if(line.Length>0)
              			{
              				cmd.CommandText = line;
              				cmd.CommandType = CommandType.Text;
              				try
              				{
              					cmd.ExecuteNonQuery();
              				}
              				catch(SqlException)
              				{
              					break;
              				}
              			}
              		}
              	}
              

              Knock out 't' from can't, You can if you think you can :cool:

              P Offline
              P Offline
              PrakashBhaskar
              wrote on last edited by
              #6

              can you plz send me step by step process to creating this setup file. I want user has to input the database server server name (select from dropdown box), user name and password thru installation shield.

              Thanks Warm Regards Prakash-B

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups