Click here to Skip to main content
15,614,439 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm trying to write a code snippet to make a simple backup from the access database in my software.

Everything looks allright (i think) but i get an error when executing the code:

error looks like this: Format of the initialization string does not conform to specification starting at index 0.

I've tried reformatting the string but i can't get it to work.
I was wondering if people here could take a look at the code i wrote?

Thanks in advance for any insights in my error!

What I have tried:

Public Class Backup
    Private backupfolderdestination As String
    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If chkVoorAkkoord.Checked Then
            btnKiesFolder.Enabled = (chkVoorAkkoord.Checked = True)
            btnMaakBackup.Enabled = (chkVoorAkkoord.Checked = True)

        End If
    End Sub

    Private Sub Backup_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    End Sub

    Private Sub btnKiesFolder_Click(sender As Object, e As EventArgs) Handles btnKiesFolder.Click

        If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
            TextBox1.Text = FolderBrowserDialog1.SelectedPath
        End If
        backupfolderdestination = FolderBrowserDialog1.SelectedPath
    End Sub

    Private Sub btnMaakBackup_Click(sender As Object, e As EventArgs) Handles btnMaakBackup.Click
            Dim cn As New OleDb.OleDbConnection(My.Settings.GekozenDatabasePad)
            Dim mydatabase As String = My.Application.Info.DirectoryPath

            System.IO.File.Copy(mydatabase & "\PatientenDatabase.accdb", String.Format(backupfolderdestination & "\bac_{0:yyyyMMdd}.backup", Date.Today))
        Catch ex As Exception
                    MsgBoxStyle.OkOnly Or MsgBoxStyle.Exclamation)
        End Try

    End Sub

    Private Sub chkVoorAkkoord_CheckedChanged(sender As Object, e As EventArgs) Handles chkVoorAkkoord.CheckedChanged

        btnKiesFolder.Enabled = (chkVoorAkkoord.Checked = True)
        btnMaakBackup.Enabled = (chkVoorAkkoord.Checked = True)

    End Sub

    Private Sub IconButton3_Click(sender As Object, e As EventArgs) Handles btnSluitVenster.Click
    End Sub
End Class
Updated 15-Dec-20 9:34am

1 solution

It's likely that you get an error because you are running an old version of your software - what you show above probably won't compile:
System.IO.File.Copy(mydatabase & "\PatientenDatabase.accdb", String.Format(backupfolderdestination & "\bac_{0:yyyyMMdd}.backup", Date.Today))

Shouldn't that be DateTime.Today?
System.IO.File.Copy(mydatabase & "\PatientenDatabase.accdb", String.Format(backupfolderdestination & "\bac_{0:yyyyMMdd}.backup", DateTime.Today))

If that doesn't fix it, then use the debugger: put a breakpoint on the first line of the method that throws the exception, and single step through to find out exactly which line is giving the problem and what data it is processing.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900