-2

I'm trying to install SQL Server 2008 using vb.net, run SQL Script and backgroundworker

Here is my code:

Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
    BackgroundWorker1.RunWorkerAsync()
End Sub

Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As
System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

    Dim pro1 As System.Diagnostics.Process
    pro1 = New System.Diagnostics.Process()
    pro1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    pro1.StartInfo.FileName = "CMD"
    pro1.StartInfo.Arguments = "/C SQLExpr_x64_enu.exe /QUIET=""TRUE"" /q /ACTION=Install /SkipRules=VSShellInstalledRule RebootRequiredCheck /HIDECONSOLE /FEATURES=SQL /INSTANCENAME=""SQLEXPRESS3"" /SECURITYMODE=""SQL"" /SQLSVCACCOUNT=""NT AUTHORITY\SYSTEM"" /SAPWD=""MYPASS"" /SQLSYSADMINACCOUNTS=""BUILTIN\ADMINISTRATORS"" /ENABLERANU=1 /AGTSVCACCOUNT=""NT AUTHORITY\SYSTEM"" /TCPENABLED=1 /ERRORREPORTING=1 /BROWSERSVCSTARTUPTYPE=""Automatic"""
    pro1.Start()

    Do While Not pro1.HasExited
        ctr = ctr + 1
        BackgroundWorker1.ReportProgress(ctr)
    Loop
End Sub

I successfully installed SQL Server using this code, but the application does not close when it is already finished.

I want a progress bar that will show the status of the process. I don't have idea how to do this.

Thanks in advance. Please leave a comment if my details are not enough to resolve my problem.

user3579618
  • 87
  • 1
  • 10
  • This just seems like a bad idea... like you're trying to use a server class database when an in-process database engine like Sql Server Compact Edition would be more appropriate. – Joel Coehoorn Mar 23 '15 at 03:02

1 Answers1

1

You could close the Process when its finished:

Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As
System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

    Dim pro1 As System.Diagnostics.Process
    pro1 = New System.Diagnostics.Process()
    pro1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
    pro1.StartInfo.FileName = "CMD"
    pro1.StartInfo.Arguments = "/C SQLExpr_x64_enu.exe /QUIET=""TRUE"" /q /ACTION=Install /SkipRules=VSShellInstalledRule RebootRequiredCheck /HIDECONSOLE /FEATURES=SQL /INSTANCENAME=""SQLEXPRESS3"" /SECURITYMODE=""SQL"" /SQLSVCACCOUNT=""NT AUTHORITY\SYSTEM"" /SAPWD=""MYPASS"" /SQLSYSADMINACCOUNTS=""BUILTIN\ADMINISTRATORS"" /ENABLERANU=1 /AGTSVCACCOUNT=""NT AUTHORITY\SYSTEM"" /TCPENABLED=1 /ERRORREPORTING=1 /BROWSERSVCSTARTUPTYPE=""Automatic"""
    pro1.Start()

    Do While Not pro1.HasExited
        ctr = ctr + 1
        BackgroundWorker1.ReportProgress(ctr)
    Loop

    'Here close the process
     pro1.Close()
End Sub

For unattended SQL installs these are the command-line arguments I use:

\SQLEXPR.exe -q /norebootchk /qn reboot=ReallySuppress addlocal=all INSTANCENAME=${instance_name} SAPWD=${password} INSTALLSQLDIR=${install_dir} SQLBROWSERACCOUNT=NT AUTHORITY\NETWORK SERVICE SQLACCOUNT=NT AUTHORITY\NETWORK SERVICE AGTACCOUNT=NT AUTHORITY\NETWORK SERVICE ASACCOUNT=NT AUTHORITY\NETWORK SERVICE RSACCOUNT=NT AUTHORITY\NETWORK SERVICE SQLBROWSERAUTOSTART=1 SQLAUTOSTART=1 AGTAUTOSTART=1 ASAUTOSTART=0 RSAUTOSTART=0 SECURITYMODE=SQL DISABLENETWORKPROTOCOLS=0 ERRORREPORTING=1 SQMREPORTING=0 ENABLERANU=0 ADDUSERASADMIN=0

To troubleshoot change qn to qb, also see how my /norebootchk is different to your RebootRequiredCheck

You may also wish to investigate if the Exit Event gets called as per Process.Exited Event and check why it isn't closing. You definitely dont want to force closing a process if it hasn't finished.


I dont think there is a way to have a Progress Bar to indicate how long an SQL Install is taking, same with estimating how long an SQL update will take. Refer to this method for a workaround: VB.NET progressbar backgroundworker.

Community
  • 1
  • 1
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321