Click here to Skip to main content
15,883,988 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Im having this problem I was able to reproduce. I create new windows form, add a new data source (an access data base file, with only one table). Then drag the table to the form. Then add a new button and the following code.

private void Test()
{
	this.table1TableAdapter.GetData();
}


private void SaveDialogTest()
{

	SaveFileDialog saveFileDialog1 = new SaveFileDialog();
        saveFileDialog1.Filter = "Text File|*.txt";
        saveFileDialog1.InitialDirectory = Application.StartupPath;
        saveFileDialog1.Title = "test";
        saveFileDialog1.ShowDialog();:mad:

        if (saveFileDialog1.FileName != "")
                 { }
}

private void button1_Click(object sender, EventArgs e)
{
        Test();
	SaveDialogTest();           
}


The table adapter is created by the designer:

private void Form1_Load(object sender, EventArgs e)
{
            // TODO: This line of code loads data into the 'testDataSet.Table1' table. You can move, or remove it, as needed.
            this.table1TableAdapter.Fill(this.testDataSet.Table1);

}





When I run the form and click on the button I get an AccessViolationException, when calling saveFileDialog1.ShowDialog().
If i move the "Test()" method inside the "Form1_Load" method everything works fine.

Also if I run the dialog first, before calling GetData() everything works fine afterwards. Like this.

SaveDialogTest();
Test();
SaveDialogTest();


This will call the second SaveDialogTest() without exception.
Also if I compile it and run it in and XP pc everything works fine.

Data Source: Microsoft Access Database File (OLE DB)
Im using Visual Studio 2008 SP1. Windows 7

Thank you.
Posted
Comments
aidin Tajadod 15-Sep-10 19:36pm    
Hi jportos,
what will happen if you change your Test function to something like this:
DataTable oDT=this.table1TableAdapter.GetData();
just a comment!

Take a look at:

https://connect.microsoft.com/VisualStudio/feedback/details/624503/oledb-operations-cause-accessviolationexception-during-savefiledialog?wa=wsignin1.0[^]

And please vote for a fix - using the I can reproduce this bug and the green tick button
 
Share this answer
 
v2
On windows 7 (32 bit) had same problem when showing the openfiledialog from a modal form loaded for the second time with data from db in it. Solution appeared to be: do not allow autoupgrade of dialog.
Dim sfv As New System.Windows.Forms.SaveFileDialog
   With sfv
     .AutoUpgradeEnabled = False
     [...]

But error came up again. Then I noticed it was apparently randomic till I realized it did not come out ifd I was able to show a saveFileDialog or an OpenfileDialog before loading any data from db.
Thus true workaround is: before load anything on the form you're going to show, display a dialog asking user to choose a path and file you *might* need after (arrrg!). After that, load data. Now your can let users, if needed, to choose path and file with dialog again...
ie:
  Private Sub frmReport_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     txtFilePathName.Text = "Export_" & Now.ToString("yyyy_MM_dd_HH_mm_ss", CultureInfo.GetCultureInfo("it-It")) & ".csv"
     txtFilePathName.Text = GetSaveFileName(txtFilePathName.Text, ".csv", "Choose a csv File to save exported data", "csv |*.csv|All |*.*")
     'now load data in forms, where you can also have a button to call again the GetSaveFileName
[...].Private Function GetSaveFileName(ByVal fileName As String,
                                    ByVal defaultExtension As String,
                                   ByVal title As String,
                                   ByVal filter As String) As String
        Dim sfv As New System.Windows.Forms.SaveFileDialog
        With sfv
            .RestoreDirectory = True
            .AddExtension = True
            .DefaultExt = defaultExtension
            .FileName = fileName
            .Title = title
            .Filter = filter
            .CheckPathExists = True
            .OverwritePrompt = True
            .ShowHelp = False
            If (.ShowDialog = DialogResult.OK) Then
                fileName = .FileName
            End If
        End With
        Return fileName
    End Function

Cimperiali
 
Share this answer
 
v3
Comments
Cimperiali 10-Mar-11 4:31am    
neeed to look twice to find the correct one....

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