Torna al Thread

Imports System.Data Imports System.Data.OleDb Imports System.Data.SqlClient Imports System.Data.Sql Imports System.Data.SqlTypes Imports System.IO.Compression Module Module1 Sub Main() Dim pathdbcompr As String = "C:\Database\archivio.mdb.zip" Dim pathdb As String = "C:\Database\archivio.mdb" Dim errore As Boolean = False Dim errore2 As Boolean = False Dim dbconn As SqlClient.SqlConnection Dim dbconn2 As OleDb.OleDbConnection If My.Computer.FileSystem.FileExists(pathdbcompr) Then Try writeLog("INIZIO") Dim errore0 As Boolean = Decomprimi(pathdbcompr, pathdb) If errore0 = True Then 'Estrazione dati Else errore = True End If Catch ex As Exception writeLog("ERRORE ESTRAZIONE DATI. " + ex.Message) errore = True dbconn2.Close() End Try If errore = False Then Try 'Inserisce i record nella tabella TAnagrafica del db di produzione Catch ex As Exception writeLog("ERRORE INSERIMENTO DATI IN TABELLA. " + ex.Message) errore2 = True dbconn.Close() End Try End If Try My.Computer.FileSystem.DeleteFile(pathdb) My.Computer.FileSystem.DeleteFile(pathdbcompr) Catch ex As Exception writeLog("ERRORE CANCELLAZIONE. " + ex.Message) End Try writeLog("FINE") End If End Sub Public Function Decomprimi(ByVal str_Origine As String, ByVal str_Destinazione As String) As Boolean Try Dim wf As FileStream Dim rf As FileStream Dim df As GZipStream Dim buff(4096) As Byte Dim int_Count As Int32 ' stream per la lettura del file compresso rf = New FileStream(str_Origine, FileMode.Open) ' stream per la scrittura del file decompresso wf = New FileStream(str_Destinazione, FileMode.Create) ' stream per la decompressione, prende in input ' lo stream per la lettura del file str_Origine df = New GZipStream(rf, CompressionMode.Decompress) ' ciclo per la lettura dei dati decompressi da df int_Count = df.Read(buff, 0, buff.Length) While int_Count > 0 ' scrive il buffer sul file str_Destinazione wf.Write(buff, 0, int_Count) int_Count = df.Read(buff, 0, buff.Length) End While ' chiude gli stream df.Close() df.Dispose() rf.Close() rf.Dispose() wf.Close() wf.Dispose() Return True Catch ex As Exception writeLog("ERRORE DECOMPRESSIONE. " + ex.Message) Return False End Try End Function Public Sub writeLog(ByVal Note As String) Dim strini As String strini = "- " & DateTime.Now.ToString & " note:" & Note Dim nomefile As String Try nomefile = "informazioni.log" Dim sw As System.IO.StreamWriter = File.AppendText(nomefile) sw.Write(strini) sw.WriteLine("") sw.Close() Catch End Try End Sub
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5