我正在尝试安装SQL Server 2008 Express,但我总是收到此错误:
SQL Server安装程序遇到以下错误:
无法识别指定的“IACCEPTSQLSERVERLICENSETERMS”设置。
错误代码0x84B40003。
我的代码在这里:
Public NotInheritable Class MSSQL2008CommandlineInstaller
Shared WithEvents process As New Process()
Private Sub New()
End Sub
Const MSSQL_SERVER_VERSION As String = "SQLSERVER2008"
Const MSSQL_INSTALLER_APP As String = "C:\Users\Hello\Desktop\SQLEXPR_x86_ENU.exe"
Public Shared Function Install(ByVal saPassword As String, ByVal instanceName As String) As Integer
Dim configFileName As String = Directory.GetCurrentDirectory() & "\MSSQLInstallationConfig.ini"
CreateMsSQLConfigurationFile(configFileName, instanceName)
Return StartInstallation(MSSQL_INSTALLER_APP, saPassword, configFileName)
End Function
Private Shared Function StartInstallation(ByVal installerApplication As String, ByVal saPassword As String, ByVal configFileName As String) As Integer
Using process
process.StartInfo = New ProcessStartInfo(installerApplication)
process.StartInfo.Arguments = "/SAPWD=""" & saPassword & """ /CONFIGURATIONFILE=""" & configFileName & """"
process.StartInfo.UseShellExecute = False
process.StartInfo.RedirectStandardOutput = True
process.StartInfo.RedirectStandardError = True
process.StartInfo.CreateNoWindow = True
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
process.Start()
process.BeginOutputReadLine()
process.BeginErrorReadLine()
process.WaitForExit()
Dim exitCode As Integer = process.ExitCode
process.Close()
Return exitCode
End Using
End Function
Public Shared Sub OnOutputDataReceived(ByVal sender As Object, ByVal e As DataReceivedEventArgs) Handles process.OutputDataReceived
If Not [String].IsNullOrEmpty(e.Data) Then
Console.WriteLine("Output: " & Convert.ToString(e.Data))
End If
End Sub
Public Shared Sub OnErrorDataReceived(ByVal sender As Object, ByVal e As DataReceivedEventArgs) Handles process.ErrorDataReceived
If Not [String].IsNullOrEmpty(e.Data) Then
Console.WriteLine("Error: " & Convert.ToString(e.Data))
End If
End Sub
Private Shared Sub CreateMsSQLConfigurationFile(ByVal fileName As String, ByVal instanceName As String)
Using configFile = New FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)
Dim writer As New StreamWriter(configFile)
writer.WriteLine("[" & MSSQL_SERVER_VERSION & "]")
writer.WriteLine("INSTANCEID=""" & instanceName & """")
writer.WriteLine("INSTANCENAME=""" & instanceName & """")
writer.WriteLine("ACTION=""Install""")
writer.WriteLine("FEATURES=SQLENGINE")
writer.WriteLine("HIDECONSOLE=""True""")
writer.WriteLine("QUIET=""False""")
writer.WriteLine("QUIETSIMPLE=""False""")
writer.WriteLine("HELP=""False""")
writer.WriteLine("INDICATEPROGRESS=""True""")
writer.WriteLine("X86=""False""")
writer.WriteLine("IACCEPTSQLSERVERLICENSETERMS=""True""")
writer.WriteLine("ROLE=""AllFeatures_WithDefaults""")
writer.WriteLine("ENU=""True""")
writer.WriteLine("ERRORREPORTING=""False""")
writer.WriteLine("SQMREPORTING=""False""")
writer.WriteLine("AGTSVCACCOUNT=""NT AUTHORITY\NETWORK SERVICE""")
writer.WriteLine("AGTSVCSTARTUPTYPE=""Automatic""")
writer.WriteLine("SQLSVCACCOUNT=""NT AUTHORITY\NETWORK SERVICE""")
writer.WriteLine("SQLSVCSTARTUPTYPE=""Automatic""")
writer.WriteLine("SECURITYMODE=""SQL""")
writer.WriteLine("ADDCURRENTUSERASSQLADMIN=""True""")
writer.WriteLine("FILESTREAMLEVEL=""0""")
writer.WriteLine("ENABLERANU=""True""")
writer.WriteLine("SQLCOLLATION=""SQL_Latin1_General_CP1_CI_AS""")
writer.WriteLine("TCPENABLED=""1""")
writer.WriteLine("NPENABLED=""1""")
writer.WriteLine("BROWSERSVCSTARTUPTYPE=""Automatic""")
writer.Flush()
End Using
End Sub
End Class
看看documentation page和this blog posting,我不明白你为什么做的不起作用,但我可以建议两件事:
这一行:
process.StartInfo.Arguments = "/SAPWD=""" & saPassword & """ /CONFIGURATIONFILE=""" & configFileName & """"
读作:
process.StartInfo.Arguments = "/IAcceptSQLServerLicenseTerms /SAPWD=""" & saPassword & """ /CONFIGURATIONFILE=""" & configFileName & """"
代替。
我最近也遇到过同样的问题。
问题是/ IAcceptSQLServerLicenseTerms选项是在2008 R2中添加的,因此在SQL Server 2008中不可用。我刚刚删除了该选项,但使用R2也应该解决问题。