[Resolvido] Código Funcionando De Maneira Estranha
Tenho o seguinte código, disparado por um botão:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim arquivo = OpenFile.ShowDialog
Dim bdAtual As String = "dados.mdb"
Dim NovoNome As String = LCase("dados" & email.GerarTextoRandomico(10) & ".mdb")
If arquivo = Windows.Forms.DialogResult.OK Then
If InStr(OpenFile.FileName, ".mdb") > 0 Then
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Tabelas(20)
Dim TabelasImportantes() As String = {"usuario", "imoveis_rgi", "tipo_imovel", "log"}
Try
conn.Open("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & OpenFile.FileName & ";")
' lista todas as tabelas do mdb
rs = conn.OpenSchema(SchemaEnum.adSchemaTables)
If Not rs.EOF Then
Dim i As Integer
Dim j As Integer
Dim validador As Integer
validador = 0
While Not rs.EOF
If Not Trim(rs.Fields("TABLE_NAME").Value) = "" And InStr(rs.Fields("TABLE_NAME").Value, "MSys", CompareMethod.Text) = 0 Then
Tabelas(i) = Trim(rs.Fields("TABLE_NAME").Value.ToString)
i += 1
End If
rs.MoveNext()
End While
i = 0
For i = LBound(Tabelas) To UBound(Tabelas)
For j = LBound(TabelasImportantes) To UBound(TabelasImportantes)
If InStr(Trim(TabelasImportantes(j)), Trim(Tabelas(i)), CompareMethod.Text) > 0 Then
validador += 1
Exit For
End If
Next
If validador = 4 Then
Exit For
End If
Next
conn.Close()
If validador = 4 Then
File.GetAccessControl(bdAtual)
'Se o banco tem essas quatro tabelas então está ok!
My.Computer.FileSystem.RenameFile(bdAtual, NovoNome)
My.Settings.last_banco = NovoNome
File.Move(OpenFile.FileName, Application.StartupPath & "\dados.mdb")
If Err.Description = "" Then
MsgBox("Banco de dados restaurado com sucesso!", MsgBoxStyle.Information, "Sucesso!")
End If
Else
MsgBox("Banco inválido", MsgBoxStyle.Critical, "Erro!")
End If
Else
MsgBox("Banco inválido", MsgBoxStyle.Critical, "Erro!")
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "Atenção")
End Try
Else
MsgBox("Você deve escolher um arquivo com a extensão .mdb", MsgBoxStyle.Exclamation, "Atenção")
End If
End If
End Sub
Esse código abre uma caixa de diálogo, onde o cliente localiza o mdb e importa-o.
Em meu computador, onde tenho o windows vista, o código funciona perfeitamente.
Mas na máquina do cliente que é windows xp sp3, e em uma máquina virtual que instalei para testar, o código além de não funcionar, exibe um msgbox escrito "dados.mdb".
Já revisei o código várias vezes e não consegui encontrar nada de errado com ele.Código Funcionando De Maneira Estranha
O erro dado na máquina do cliente é:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************ Exception Text ************
System.IO.FileNotFoundException: dados.mdb
at System.Security.AccessControl.NativeObjectSecurity.CreateInternal(ResourceType resourceType, Boolean isContainer, String name, SafeHandle handle, AccessControlSections includeSections, Boolean createByName, ExceptionFromErrorCode exceptionFromErrorCode, Object exceptionContext)
at System.Security.AccessControl.FileSystemSecurity..ctor(Boolean isContainer, String name, AccessControlSections includeSections, Boolean isDirectory)
at System.Security.AccessControl.FileSecurity..ctor(String fileName, AccessControlSections includeSections)
at ControleRGI.backDatabase.btnPorArquivo_Click(Object sender, EventArgs e) in D:\Documentos\Visual Studio 2005\Projects\ControleRGI\ControleRGI\backDatabase.vb:line 252
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************ Loaded Assemblies ************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
ControleRGI
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Arquivos%20de%20programas/FORTALDESIGN/Controle%20RGI/ControleRGI.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
ADODB
Assembly Version: 7.0.3300.0
Win32 Version: 7.10.6070
CodeBase: file:///C:/Arquivos%20de%20programas/FORTALDESIGN/Controle%20RGI/ADODB.DLL
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
CrystalDecisions.Windows.Forms
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.Windows.Forms/10.2.3600.0__692fbea5521e1304/CrystalDecisions.Windows.Forms.dll
----------------------------------------
CrystalDecisions.Shared
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.Shared/10.2.3600.0__692fbea5521e1304/CrystalDecisions.Shared.dll
----------------------------------------
CrystalDecisions.ReportSource
Assembly Version: 10.2.3600.0
Win32 Version: 10.2.51014.0
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/CrystalDecisions.ReportSource/10.2.3600.0__692fbea5521e1304/CrystalDecisions.ReportSource.dll
----------------------------------------
System.Web
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll
----------------------------------------
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
************ JIT Debugging ************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Discussão (2)
Carregando comentários...