3,5 postgresql cast exception

Posts   
 
    
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 23-Aug-2012 16:53:26   

Hi,

I'm trying to execute the pure sql command using the following code:

using (DataAccessAdapterBase adapter = CreateAdapter())
            {
                adapter.StartTransaction(IsolationLevel.Serializable, "GetQueuedTask");

                SqlDataReader dr = (SqlDataReader)adapter.FetchDataReader(query, CommandBehavior.Default);
}

But unfortunateley method FetchDataReader returns the following exception:

Unable to cast object of type 'Npgsql.NpgsqlConnection' to type 'System.Data.SqlClient.SqlConnection'.

What I'm doing wrong?

Best regards, MiloszeS

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Aug-2012 19:20:46   

Don't cast the return of the FetchDataReader. try the following:

IDataReader dr = adapter.FetchDataReader(query, CommandBehavior.Default);
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 24-Aug-2012 10:01:36   

the cast error is obvious, postgresql uses npgsql, not sqlclient.

Frans Bouma | Lead developer LLBLGen Pro
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 24-Aug-2012 16:27:11   

Yes, it obvious, but it is thrown by FetchDataReader - I cannot use it with postgresql?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 24-Aug-2012 19:10:19   

miloszes wrote:

Yes, it obvious, but it is thrown by FetchDataReader - I cannot use it with postgresql?

Unless you show us a stacktrace, it's not clear it's thrown by FetchDataReader. I'm pretty sure the cast is on the line in your code calling FetchDataReader, not inside the FetchDataReader itself.

Frans Bouma | Lead developer LLBLGen Pro
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 27-Aug-2012 14:06:05   
 at System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value)
   at SD.LLBLGen.Pro.ORMSupportClasses.Query.set_Connection(DbConnection value) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Query\Query.cs:line 383
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateActiveConnectionInQueryIfRequired(IQuery queryToExecute, Boolean forceConnectionSet) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5533
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.PrepareQueryExecution(IQuery queryToExecute, Boolean forceConnectionSet) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5557
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchDataReader(IRetrievalQuery queryToExecute, CommandBehavior readerBehavior) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 1531

Current exc.msg:

Unable to cast object of type 'SD.Tools.OrmProfiler.Interceptor.ProfilerDbConnection' to type 'System.Data.SqlClient.SqlConnection'.

miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 27-Aug-2012 14:09:07   

But when I disable the profiler I receive:

at System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value)
   at SD.LLBLGen.Pro.ORMSupportClasses.Query.set_Connection(DbConnection value) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Query\Query.cs:line 383
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateActiveConnectionInQueryIfRequired(IQuery queryToExecute, Boolean forceConnectionSet) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5533
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.PrepareQueryExecution(IQuery queryToExecute, Boolean forceConnectionSet) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 5557
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchDataReader(IRetrievalQuery queryToExecute, CommandBehavior readerBehavior) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.5\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 1531

Unable to cast object of type 'Npgsql.NpgsqlConnection' to type 'System.Data.SqlClient.SqlConnection'.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 27-Aug-2012 15:39:09   

The 'query' passed to the method is created using the SQL Server DQE, while the adapter is for Postgresql. Please check this.

Frans Bouma | Lead developer LLBLGen Pro
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 12-Sep-2012 15:41:43   

Yep, it was my fault.