SQL SMO 라이브러리에 간단한 인터페이스를 작성하여 Inno 설치 스크립트에서 설치 중에 SQL Server를 중지하고 시작할 수 있습니다. 내 개발 기계는 64 비트 프로세서 기계입니다. 관리 코드는 .NET 용 DllExport, .NET 4.0 대상 및 x86 플랫폼 용 컴파일을 사용하여 Visual Basic으로 작성됩니다. Inno Setup 5.5.9 유니 코드 버전을 사용하고 있습니다.Inno 설치 .NET DLL 호출이 64 비트에서 작동하고 32 비트에서 실패 함
설치 실행 파일은 내 개발 컴퓨터와 내가 시도한 다른 64 비트 프로세서에서 잘 작동합니다. 32 비트 프로세서 시스템에서 실행 파일을 실행할 때 오류가 발생합니다.
External Exception E0434352
꽤 도움이되는 일반입니다. 두 시스템 모두 Windows 10이지만 다른 Windows 버전 및 64 비트 및 32 비트 시스템에서도이 기능을 시험해 보았습니다. 그래서 32 비트 실행을 방해하기 위해 무엇을 했습니까?
이노 설정 코드 :
[Files]
Source: "fiSqlSmoLib2\bin\x86\Debug\fiSqlSmoLib2.dll"; DestDir: "{app}"; \
Flags: nocompression 32bit
[Code]
function StartSql(machineName, sqlServerName: AnsiString): Integer;
external '[email protected]:fiSqlSmoLib2.dll stdcall setuponly delayload';
function StopSql(machineName, sqlServerName: AnsiString): Integer;
external '[email protected]:fiSqlSmoLib2.dll stdcall setuponly delayload';
function InitializeSetup(): Boolean;
var
SQLresultCode : Integer;
Computer : String;
SQLServer : String;
begin
Computer := GetComputerNameString;
SQLServer := 'FACTORYINSITE';
try
SQLresultCode := StopSql(Computer, SQLServer);
except
ShowExceptionMessage;
exit;
end;
try
SQLresultCode := StartSql(Computer, SQLServer);
except
ShowExceptionMessage;
exit;
end;
end;
VBA 코드 :
는Imports System.Runtime.InteropServices
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common
Imports Microsoft.SqlServer.Management.Smo.Wmi
Imports RGiesecke.DllExport
Public Class fiSqlSmo
<DllExport("StartSql", CallingConvention.StdCall)> _
Public Shared Function StartSql(<MarshalAs(UnmanagedType.LPStr)> machineName As String, <MarshalAs(UnmanagedType.LPStr)> sqlServerName As String) As Integer
Dim mc As ManagedComputer
Dim Svc As Service
Dim svcState As ServiceState
Try
mc = New ManagedComputer(machineName)
Svc = mc.Services("MSSQL$" + sqlServerName)
Catch ex As Exception
Return ServiceState.Unknown
End Try
Try
svcState = Svc.ServiceState
Catch ex As Exception
Return ServiceState.Unknown
End Try
If (Svc.ServiceState <> ServiceState.Running) Then
Svc.Start()
End If
Return svcState
End Function
<DllExport("StopSql", CallingConvention.StdCall)> _
Public Shared Function StopSql(<MarshalAs(UnmanagedType.LPStr)> machineName As String, <MarshalAs(UnmanagedType.LPStr)> sqlServerName As String) As Integer
Dim mc As ManagedComputer
Dim Svc As Service
Dim svcState As ServiceState
Try
mc = New ManagedComputer(machineName)
Svc = mc.Services("MSSQL$" + sqlServerName)
Catch ex As Exception
Return ServiceState.Unknown
End Try
Try
svcState = Svc.ServiceState
Catch ex As Exception
Return ServiceState.Unknown
End Try
If (Svc.ServiceState = ServiceState.Running) Then
Svc.Stop()
End If
Return svcState
End Function
End Class
SMO가 기본적으로 설치되지 않았는지, 실패한 시스템에서 사용할 수 있습니까? 코드가 해당 컴퓨터의 콘솔 앱에서 작동합니까? 당신은 간단하게'ServiceController'를 사용하거나 [Pascal Script를 사용하여] .Net 의존성을 제거 할 수있는 MSSQL 서비스를 시작/중지하기 위해 SMO가 필요하지 않습니다. (http://stackoverflow.com/questions/2456987/upgrading-windows-service- using-inno-setup) –
또는 문제를 디버그하기 위해 VB.NET 코드에서 예외를 잡아 로그에 기록하십시오. –
SMO가 테스트 머신에 설치되어 있다고 생각합니다.하지만 이는 좋은 제안입니다. 콘솔 앱을 사용해 볼게. SQL 서버가 설치 코드와 다른 노드에 있거나 아마도 Azure에서 SMO가 가장 좋은 방법이라고 생각할 수 있습니다. 전체 설치에서는 SQL 서버에 로그인하여 스크립트를 실행하므로 이것이 실행되고 있는지 확인해야합니다. – jphoekstra