Problem with ADO.NET and dao pia in the same project

E

einat lapid

I have a wierd problem working with ADO.NET and DAO PIA in the same
project - it seems that ADO.NET is causing the DAO objects

to be destructed. Once I open ADO.NET connection, the DAO objecucts seems
destructed (at least thier native part) and I get

Unhandled Exception: System.Runtime.InteropServices.COMException
(0x800A0D5C): O
bject invalid or no longer set.

The funny thing about it is that it happened only in release build when run
outside of the VS 2005 IDE.

The repro code is below. Any idea how to work around this problem ?



Thanks,

Einat



using System;

using System.Text;

using dao;

using System.Data;

using System.Data.SqlClient;

using System.Runtime.InteropServices;



namespace AccessDataTransfer

{

class Program

{

static void Main(string[] args)

{

String Sourcedbstr = "c:\\1.mdb";

String DestConnectionStr = @"Data Source=localhost;Integrated
Security=SSPI;Initial Catalog=pubs";

String TableName = "Foo";



//dao connection

dao.DBEngineClass engineClass = new DBEngineClass();

dao.Workspace workSpace =
engineClass.CreateWorkspace("WorkSpace", "Admin", "",
WorkspaceTypeEnum.dbUseJet);

dao.Database Sourcedb = workSpace.OpenDatabase(Sourcedbstr,
Type.Missing, true, null);

dao.Recordset SourceRecordSet =
Sourcedb.OpenRecordset(TableName, Type.Missing, Type.Missing, Type.Missing);

//ADO.NET connection that invalidate the DAO objects

SqlConnection DestConnection = new
SqlConnection(DestConnectionStr);

DestConnection.Open();









Now manipulate dao object and fails

TableDef tblDef = Sourcedb.TableDefs[TableName]; //fails
here



}



}

}
 
W

William \(Bill\) Vaughn

And you're using DAO because?

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
G

Gil Lapid Shafriri

I need to move data from Access (also Access 97) to SQL


William (Bill) Vaughn said:
And you're using DAO because?

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________

einat lapid said:
I have a wierd problem working with ADO.NET and DAO PIA in the same
project - it seems that ADO.NET is causing the DAO objects

to be destructed. Once I open ADO.NET connection, the DAO objecucts seems
destructed (at least thier native part) and I get

Unhandled Exception: System.Runtime.InteropServices.COMException
(0x800A0D5C): O
bject invalid or no longer set.

The funny thing about it is that it happened only in release build when
run outside of the VS 2005 IDE.

The repro code is below. Any idea how to work around this problem ?



Thanks,

Einat



using System;

using System.Text;

using dao;

using System.Data;

using System.Data.SqlClient;

using System.Runtime.InteropServices;



namespace AccessDataTransfer

{

class Program

{

static void Main(string[] args)

{

String Sourcedbstr = "c:\\1.mdb";

String DestConnectionStr = @"Data Source=localhost;Integrated
Security=SSPI;Initial Catalog=pubs";

String TableName = "Foo";



//dao connection

dao.DBEngineClass engineClass = new DBEngineClass();

dao.Workspace workSpace =
engineClass.CreateWorkspace("WorkSpace", "Admin", "",
WorkspaceTypeEnum.dbUseJet);

dao.Database Sourcedb = workSpace.OpenDatabase(Sourcedbstr,
Type.Missing, true, null);

dao.Recordset SourceRecordSet =
Sourcedb.OpenRecordset(TableName, Type.Missing, Type.Missing,
Type.Missing);

//ADO.NET connection that invalidate the DAO objects

SqlConnection DestConnection = new
SqlConnection(DestConnectionStr);

DestConnection.Open();









Now manipulate dao object and fails

TableDef tblDef = Sourcedb.TableDefs[TableName]; //fails
here



}



}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top