EDIT: Problem selbst gelöst.
Habe das DataSet importiert, aber nichts weiter programmiert als nur den Import.
Weil dann nichts passiert ist, habe ich den Button erneut geklickt und der readxml schlägt fehl, weils DataSet schon gefüllt ist.
SORRY!
Falls das zu löschen geht - bitte machen.
Hallo
Ich speichere in meinem Programm ein DataSet nach xml und nutze dafür eine Cryptostream Verschlüsselung:
Spoiler anzeigen
Diese xml Datei möchte ich nun in einem anderen Programm einlesen (ich möchte ein kleines Programm schreiben und EINMAL die Inhalte von zwei DataTable in eine neue xml zu kopieren.
Hierzu habe ich im neuen Programm ebenfalls ein DataSet mit dem Namen DTSSettings erzeugt und die DataTables aus dem Programm hier reinkpoiert (Strg+a / Strg+C / Strg+V)
Dann habe ich folgenden Code hinzugefügt: (Die Variablen _OldPW und _OldFile sind dabei korrekt gefüllt (Das habe ich getestet)
Spoiler anzeigen
Ich erhalte aber nur den Fehler:
Hier der gesamte Fehlertext:
Spoiler anzeigen
Was mache ich falsch?
Habe das DataSet importiert, aber nichts weiter programmiert als nur den Import.
Weil dann nichts passiert ist, habe ich den Button erneut geklickt und der readxml schlägt fehl, weils DataSet schon gefüllt ist.
SORRY!
Falls das zu löschen geht - bitte machen.
Hallo
Ich speichere in meinem Programm ein DataSet nach xml und nutze dafür eine Cryptostream Verschlüsselung:
VB.NET-Quellcode
- Private Sub FrmMainForm_Closed(sender As Object, e As EventArgs) Handles Me.Closed
- SaveSettings()
- End Sub
- Public Sub SaveSettings()
- 'ggf. vorhandene SettingsFile löschen
- If File.Exists(_SettingsFile) Then File.Delete(_SettingsFile)
- 'Verschlüsselung starten und seichern der xml
- Using cS As CryptoStream = GetEncryptionStream()
- Me.DtsSettings.WriteXml(cS)
- End Using
- End Sub
- Private Function GetEncryptionStream() As CryptoStream
- Dim key As New Rfc2898DeriveBytes(_MasterPassword, New Byte() {10, 255, 255, 7, 14, 16, 23, 155})
- Dim x As New TripleDESCryptoServiceProvider()
- x.Key = key.GetBytes(x.KeySize \ 8)
- x.IV = key.GetBytes(x.BlockSize \ 8)
- Dim fS As FileStream = New FileStream(_SettingsFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None)
- Return New CryptoStream(fS, x.CreateEncryptor(), CryptoStreamMode.Write)
- End Function
Diese xml Datei möchte ich nun in einem anderen Programm einlesen (ich möchte ein kleines Programm schreiben und EINMAL die Inhalte von zwei DataTable in eine neue xml zu kopieren.
Hierzu habe ich im neuen Programm ebenfalls ein DataSet mit dem Namen DTSSettings erzeugt und die DataTables aus dem Programm hier reinkpoiert (Strg+a / Strg+C / Strg+V)
Dann habe ich folgenden Code hinzugefügt: (Die Variablen _OldPW und _OldFile sind dabei korrekt gefüllt (Das habe ich getestet)
VB.NET-Quellcode
- Private Sub BTNStartImport_Click(sender As Object, e As EventArgs) Handles BTNStartImport.Click
- 'alte Daten Laden
- LoadSettings(_OldPW, _OldFile)
- End Sub
- Private Sub LoadSettings(Passwort As String, DataFile As String)
- If File.Exists(DataFile) Then
- Using cS As CryptoStream = GetDecryptionStream(Passwort, DataFile)
- DtsSettings.ReadXml(cS)
- End Using
- End If
- End Sub
- Private Function GetDecryptionStream(Passwort As String, DataFile As String) As CryptoStream
- Dim key As New Rfc2898DeriveBytes(Passwort, New Byte() {10, 255, 255, 7, 14, 16, 23, 155})
- Dim x As New TripleDESCryptoServiceProvider()
- x.Key = key.GetBytes(x.KeySize \ 8)
- x.IV = key.GetBytes(x.BlockSize \ 8)
- Dim fS As FileStream = New FileStream(DataFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
- Return New CryptoStream(fS, x.CreateDecryptor(), CryptoStreamMode.Read)
- End Function
Ich erhalte aber nur den Fehler:
Ungültige Daten auf Stammebene. Zeile 1, Position 1.
beim Ausführen von Zeile 9Hier der gesamte Fehlertext:
System.Xml.XmlException
HResult=0x80131940
Nachricht = Ungültige Daten auf Stammebene. Zeile 1, Position 1.
Quelle = System.Xml
Stapelüberwachung:
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving)
at System.Data.DataSet.ReadXml(Stream stream)
at DasProgrammImporter.frmMain.LoadSettings(String Passwort, String DataFile) in C:\Users\flori\Documents\Visual Studio 2022\Programme\DasProgrammImporter\DasProgrammImporter\Form1.vb:line 61
at DasProgrammImporter.frmMain.BTNStartImport_Click(Object sender, EventArgs e) in C:\Users\flori\Documents\Visual Studio 2022\Programme\DasProgrammImporter\DasProgrammImporter\Form1.vb:line 44
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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at DasProgrammImporter.My.MyApplication.Main(String[] Args) in :line 83
HResult=0x80131940
Nachricht = Ungültige Daten auf Stammebene. Zeile 1, Position 1.
Quelle = System.Xml
Stapelüberwachung:
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlReader.MoveToContent()
at System.Data.DataSet.ReadXml(XmlReader reader, Boolean denyResolving)
at System.Data.DataSet.ReadXml(Stream stream)
at DasProgrammImporter.frmMain.LoadSettings(String Passwort, String DataFile) in C:\Users\flori\Documents\Visual Studio 2022\Programme\DasProgrammImporter\DasProgrammImporter\Form1.vb:line 61
at DasProgrammImporter.frmMain.BTNStartImport_Click(Object sender, EventArgs e) in C:\Users\flori\Documents\Visual Studio 2022\Programme\DasProgrammImporter\DasProgrammImporter\Form1.vb:line 44
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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at DasProgrammImporter.My.MyApplication.Main(String[] Args) in :line 83
Was mache ich falsch?
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „DerSmurf“ ()