COM problems with connecting to database

Pendejo

New member
Joined
May 5, 2003
Messages
4
Okay, this is my problem.

I have to write a serviced component to access an MS Access Database through ODBC. I created a system DSN in the ODBC Manager of Windows (xp service pack1). I wrote a little client to see if this system DSN was working and it worked.

Next I wrote a class with exactly the same code to access the database and deployed it as a serviced component. This is my code

-----------------------------------------------------
using System;
using System.EnterpriseServices;
using System.Collections;
using Microsoft.Data.Odbc;

[assembly: ApplicationName("LessenRooster")]

[assembly: ApplicationActivation(ActivationOption.Server)]

namespace thesis
{
public interface ILessenroosterCOM
{
string dagProgramma();
}



[Transaction(TransactionOption.Required)]
[JustInTimeActivation]

public class LessenroosterCOM : ServicedComponent, ILessenroosterCOM
{
public LessenroosterCOM(){}

public string dagProgramma()
{
string result;
string con = "dsn=tester;";
string sql = "Select * from reservatie";

OdbcConnection connection = new OdbcConnection(con);
OdbcCommand cmd = new OdbcCommand(sql);

cmd.Connection = connection;
try
{
connection.Open();
OdbcDataReader reader = cmd.ExecuteReader();

reader.Read();
DateTime datum2 = reader.GetDateTime(2);
result = datum2.ToString();

}

catch(Exception exc)
{
result = exc.ToString();
}
finally
{
connection.Close();
}
return result;
}
}
}

---------------------------------------------------

However, when I write a client to access the Database with this component I get following error.


Microsoft.Data.Odbc.OdbcException: ERROR [25000] [Microsoft][ODBC-stuurprogrammabeheer] De registratie van de transactie van het aanroepend object is mislukt

(Translation: the registration of the transaction of the calling object failed)

ERROR [IM006] [Microsoft][ODBC-stuurprogrammabeheer] SQLSetConnectAttr van het stuurprogramma is mislukt

(Translation: SQLSetConnectAttr driver failed)

at Microsoft.Data.Odbc.OdbcConnection.Open()
at thesis.LessenroosterCOM.dagProgramma() in d:\development-area\thesis.net\lessenroostercom\class1.cs:line 42


I looked this failure code up on the internet and I most of the time I found information that said that the problem was with the fact that the database would not be a system resource. However, I created the dsn as a system dsn. I just dont get.
Can anybody please help me,
thanx in advance

PS: I tried to do it with oledb, but it failed also, same scenario.
 
Back
Top