Results 1 to 2 of 2

Thread: deploying sql server 2005 express with my vb.net application

  1. #1

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    deploying sql server 2005 express with my vb.net application

    Hi Guys,

    I have a main application, a class library and a setup project that has the primary output of both the above.

    The class library has a class that determines if dql server 2005 express is installed and if not it installs sql server express. here is a code snippet:

    Code:
    Private Function BuildCommandLine() As String
            Dim strCommandLine As StringBuilder = New StringBuilder
    
            If (Not String.IsNullOrEmpty(m_installSqlDir)) Then
                strCommandLine.Append("INSTALLSQLDIR=""").Append(m_installSqlDir).Append("""")
            End If
    
            If (Not String.IsNullOrEmpty(m_installSqlSharedDir)) Then
                strCommandLine.Append("INSTALLSQLSHAREDDIR=""").Append(m_installSqlSharedDir).Append("""")
            End If
    
            If (Not String.IsNullOrEmpty(m_installSqlDataDir)) Then
                strCommandLine.Append("INSTALLSQLDATADIR=""").Append(m_installSqlDataDir).Append("""")
            End If
    
            If (Not String.IsNullOrEmpty(m_addLocal)) Then
                strCommandLine.Append(" ADDLOCAL=""").Append(m_addLocal).Append("""")
            End If
    
            If (m_sqlAutoStart) Then
                strCommandLine.Append(" SQLAUTOSTART=1")
            Else
                strCommandLine.Append(" SQLAUTOSTART=0")
            End If
    
            If (m_sqlBrowserAutoStart) Then
                strCommandLine.Append(" SQLBROWSERAUTOSTART=1")
            Else
                strCommandLine.Append(" SQLBROWSERAUTOSTART=0")
            End If
    
            If (String.IsNullOrEmpty(m_sqlBrowserAccount)) Then
                strCommandLine.Append("SQLBROWSERACCOUNT=""").Append(m_sqlBrowserAccount).Append("""")
            End If
    
            If (Not String.IsNullOrEmpty(m_sqlBrowserPassword)) Then
                strCommandLine.Append("SQLBROWSERPASSWORD=""").Append(m_sqlBrowserPassword).Append("""")
            End If
    
            If (Not String.IsNullOrEmpty(m_sqlAccount)) Then
                strCommandLine.Append(" SQLACCOUNT=""").Append(m_sqlAccount).Append("""")
            End If
    
            If (Not String.IsNullOrEmpty(m_sqlPassword)) Then
                strCommandLine.Append(" SQLPASSWORD=""").Append(m_sqlPassword).Append("""")
            End If
    
            If (m_sqlSecurityMode = True) Then
                strCommandLine.Append(" SECURITYMODE=SQL")
            End If
    
            If (Not String.IsNullOrEmpty(m_saPassword)) Then
                strCommandLine.Append(" SAPWD=""").Append(m_saPassword).Append("""")
            End If
    
            If (Not String.IsNullOrEmpty(m_sqlCollation)) Then
                strCommandLine.Append(" SQLCOLLATION=""").Append(m_sqlCollation).Append("""")
            End If
    
            If (m_disableNetworkProtocols = True) Then
                strCommandLine.Append(" DISABLENETWORKPROTOCOLS=1")
            Else
                strCommandLine.Append(" DISABLENETWORKPROTOCOLS=0")
            End If
    
            If (m_errorReporting = True) Then
                strCommandLine.Append(" ERRORREPORTING=1")
            Else
                strCommandLine.Append(" ERRORREPORTING=0")
            End If
    
            Return strCommandLine.ToString
    
        End Function
    
        Public Function InstallExpress() As Boolean
            Dim myProcess As Process = New Process
            myProcess.StartInfo.FileName = m_sqlExpressSetupFileLocation
            myProcess.StartInfo.Arguments = "/qb " + BuildCommandLine()
    
            '     /qn -- Specifies that setup run with no user interface.
            '               /qb -- Specifies that setup show only the basic 
            'user interface. Only dialog boxes displaying progress information are 
            'displayed. Other dialog boxes, such as the dialog box that asks users if 
            'they want to restart at the end of the setup process, are not displayed.
    
            myProcess.StartInfo.UseShellExecute = False
    
            Return myProcess.Start
    
        End Function
    My problem is. When I run the setup it must install sql server then run a script that creates the database etc. this is a snippet from my other class:

    Code:
    ei.InstallExpress()
    
                Dim success As Boolean = tcon.TestConnection(".\SQLEXPRESS", "master")
    
                If (success) Then
    
                    tcon.RunAllSqlSriptsInDirectory()
    
                End If
    as you can see I call the InstallExpress function to do the install of sql. Then once that is complete I must run the script to create the database.

    However, my setup finsihes while the sqlexpress install is still running and I have a feeling the script gets executed before sql express is installed and I therefore cannot login once I try to oprn my application.

    How do I fix this? please please help. when I ran the setup again after sql installed it created my database fine.

    ***
    also if I add code to wait until the sql install process is done and then execute the script, the sql installer fails saying "Another installation is already in progress. Complete that installation before proceeding with this install"

    Please please advise me. I worked so hard on this now I'm at a dead end again

  2. #2
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: deploying sql server 2005 express with my vb.net application

    SQL express will start installing after MSI of application completes the installation. You cannot run other installer from MSI setup file.

    I had a similar situation. What I did was after the installation completed, clicking on the icon in the desktop ( opening your application) open a DB settings form.

    We used to have option to create new DB , execute script to create tables and SPs in this settings form.This form will open for the first time on installation. After that the login form will open up.

    Hope this will give you an alternate way ....
    thanks
    amrita

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width