Hi guys,
When developing my application, I need to switch between SQL CE mode and SQL Server 2005 mode. My LLBLGen project was originally generated for SQL CE. I saw there is a method in HelperClasses.DBUtils.cs named CreateConnection and made a little change in it. Here are changes:
public static DbConnection CreateConnection(string connectionString)
{
if (!NetWork)
{
return new SqlCeConnection(connectionString);
}
else
{
return new SqlConnection(connectionString);
}
}
I also passed the proper connection string for this method. But when the application start, I got an exeption
System.InvalidCastException: Unable to cast object of type 'System.Data.SqlClient.SqlConnection' to type 'System.Data.SqlServerCe.SqlCeConnection'.
at System.Data.SqlServerCe.SqlCeCommand.set_DbConnection(DbConnection value)
at System.Data.Common.DbCommand.System.Data.IDbCommand.set_Connection(IDbConnection value)
at SD.LLBLGen.Pro.ORMSupportClasses.Query..ctor(IDbConnection connectionToUse, IDbCommand commandToUse)
at SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery..ctor(IDbConnection connectionToUse, IDbCommand commandToUse)
at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Boolean relationsSpecified, Boolean sortClausesSpecified)
at SD.LLBLGen.Pro.ORMSupportClasses.DynamicQueryEngineBase.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause)
at SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreatePagingSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.CreateQueryFromElements(ITransaction transactionToUse, IEntityFields fields, IPredicate filter, IRelationCollection relations, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IGroupByCollection groupByClause, Boolean allowDuplicates, Int32 pageNumber, Int32 pageSize)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAsDataTableAction(IEntityFields fieldsToReturn, DataTable tableToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Boolean allowDuplicates, IGroupByCollection groupByClause, ITransaction transactionToUse, Int32 pageNumber, Int32 pageSize)
at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAsDataTableAction(Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Int32 pageNumber, Int32 pageSize)
I used the following code in CheckExistingData() method
dsCheckUser.Tables.Add(UserCollection.GetMultiAsDataTable(null, 0, null));
.
Any idea about this?
Thanks in advance.