Deploy vb.net project with sql database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajanji
    New Member
    • May 2008
    • 31

    #1

    Deploy vb.net project with sql database

    I have an vb.net application that I want to install on client machine. The backend is SQL server. Could I make up a setup package that would deploy an application that includes the database with all the stored procedures and tables? The client pc do not have sql server installed therer.

    If I could where would I look to get started ...


    Regards,
    Rajan Arora
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    #2
    Step1
    Include SQL Express in the installer prerequisites

    Step2
    Script out the SQL Database. Execute the database script on the program first startup.

    Comment

    • rajanji
      New Member
      • May 2008
      • 31

      #3
      i have included the sql express in the installer prequisites .. but m unable to execute the sql scripts. can u plz tell me how to execute the database scripts on the client machine....

      Comment

      • sashi
        Recognized Expert Top Contributor
        • Jun 2006
        • 1749

        #4
        Hi Rajanji,

        Kindly refer to below attached code segment, hope it helps.

        Code:
          string sqlConnectionString = "Data Source=FIRSTONE;User ID=sa; Persist Security Info=True;";
        
          FileInfo file = new FileInfo("name_of_the_sql_script.sql");
          string script = file.OpenText().ReadToEnd();
          string rscript = script.Replace("GO", "");
        
          SqlConnection conn = new SqlConnection(sqlConnectionString);
          SqlCommand cmd = new SqlCommand(rscript, conn);
          cmd.Connection.Open();
        
          cmd.ExecuteNonQuery();
        
          cmd.Dispose();

        Comment

        • rajanji
          New Member
          • May 2008
          • 31

          #5
          m not understanding where to put this script file and how to execute it on program first startup ...
          1. Can u please tell me whats the procedure for the same and
          2. Will it prevent to run the sql script everytime my application starts after the database and tables are created ...

          Comment

          • sashi
            Recognized Expert Top Contributor
            • Jun 2006
            • 1749

            #6
            Step 1
            You need to write a simple procedure to check if the database already exist.

            Example 1

            Code:
            Public Shared Function CheckDatabaseExists(ByVal Server As String, ByVal Database As String) As Boolean
                    Dim connString As String = ("Data Source="  _
                                + (Server + ";Initial Catalog=Master;Integrated Security=True;"))
                    Dim cmdText As String = ("SELECT * FROM master.dbo.sysdatabases WHERE NAME=\'"  _
                                + (Database + "\'"))
                    Dim bRet As Boolean = false
                    Using sqlConnection As SqlConnection = New SqlConnection(connString)
                    sqlConnection.Open
                    Using sqlCmd As SqlCommand = New SqlCommand(cmdText, sqlConnection)
                    Using reader As SqlDataReader = sqlCmd.ExecuteReader
                    bRet = reader.HasRows
                    End Using
                    End Using
                    End Using
                    Return bRet
                End Function
            Step 2
            If step1 returns false, execute the script.

            Comment

            • aniruddhbhatt
              New Member
              • Sep 2010
              • 2

              #7
              hey man this is your question of many time ago.

              if you have any solution of this problem please tell me about it.
              please man



              I have an vb.net application that I want to install on client machine. The backend is SQL server. Could I make up a setup package that would deploy an application that includes the database with all the stored procedures and tables? The client pc do not have sql server installed therer.

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Aniruddhbhatt,

                You are on the right track.

                While I have not created as setup project myself I am aware that they should include scripts that can be executed to create your database.

                There are numerous third party applications that can help you to create a setup application that will help you with this.

                -Frinny

                Comment

                Working...