- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
LLBLGenProDataSource2 and alternate catalogs
Joined: 13-Jan-2006
I would like to use a variety of databases for testing purposes with different names than the production database. I can switch easily between them by the changing "Main.ConnectionString" key in my web.config to a different Initial Catalog.
However, what do I do for my LLBLGenDataSource2 objects that are defined declaratively? The TypedViewName property seems to have the catalog name embedded into it. Must I write some code for all pages using this control and set the TypeViewName programatically based on the Main.ConnectionString being used?
Joined: 13-Jan-2006
Tried it out now. Sorry, but it doesn't work. Code is using the old database ("Standards" in my case).
Here's what I have in my web.config:
<configuration>
<configSections>
<section name="SqlServerCatalogNameOverwrites" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<SqlServerCatalogNameOverwrites>
<add key="Standards" value="StandardsTest1" />
</SqlServerCatalogNameOverwrites>
<appSettings>
<!-- Connection String used by llblGen -->
<add key="Main.ConnectionString" value="data source=COMPAQ-EVO;initial catalog=Standards;User ID=********;Password=*********;persist security info=False;packet size=4096"/>
...
Could it be that SqlServerCatalogNameOverwrites doesn't work with declared instances of datasources (LLBLGenProDataSource2)?
Joined: 13-Jan-2006
ORMSUpportClasses is 2.0.7.319 DQESQL is 2.0.0.60814
My datasource declaration is:
<llblgenpro:LLBLGenProDataSource2
ID="LLBLGenProDataSource2_1"
CacheLocation="Session"
AdapterTypeName="Standards.DatabaseSpecific.DataAccessAdapter, StandardsDBSpecific"
runat="server"
LivePersistence="true"
DataContainerType="EntityCollection"
EntityFactoryTypeName="Standards.FactoryClasses.OrganizationEntityFactory, Standards">
<SelectParameters>
<asp:Parameter DefaultValue="4" Name="Id" Type="Int32" />
</SelectParameters>
</llblgenpro:LLBLGenProDataSource2>
The error I get is something like "Database is offline" (which it is). I tried changing ", Standards" at the end of EntityFactoryTypeName to "StandardsTest1" and I get some sort of runtime object type error.
In the designer I have both the "Standards" db and the "StandardsTest1" db added to the project (do I even need to do that). See the screenshot.
Filename | File size | Added on | Approval |
---|---|---|---|
2cats.JPG | 26,347 | 09-Jun-2007 03:40.07 | Approved |
You should add to the project the catalog to which you want to map entities to. The other catalog(s) can be removed. (catalog explorer, right click -> remove)
If all entities are mapped onto tables in Standards, then initially all queries will embed that name. If you want to target a different catalog you need to use catalogname overwriting. Your web.config file shows that you do that.
However as DvK says: you refer to Standards in your connection string, so sqlserver will connect with that db first. If that doesn't exist, you'll get an error.
Joined: 13-Jan-2006
No, that (changing the connection string in addition to having an overwrites section) doesn't work either. Even if I change the connection string to my alternate catalog it appears that my llblgenprodatasource2 control STILL wants to use the original connection string.
Here's the markup for the data source:
<llblgenpro:LLBLGenProDataSource2
ID="LLBLGenProDataSource2_1"
CacheLocation="Session"
AdapterTypeName="Standards.DatabaseSpecific.DataAccessAdapter, StandardsDBSpecific"
runat="server"
LivePersistence="true"
DataContainerType="EntityCollection"
EntityFactoryTypeName="Standards.FactoryClasses.OrganizationEntityFactory, Standards">
<SelectParameters>
<asp:Parameter DefaultValue="4" Name="Id" Type="Int32" />
</SelectParameters>
</llblgenpro:LLBLGenProDataSource2>
I have absolutely confirmed that the connection string is correctly set to the ALTERNATE database by displaying a debug string at the top of all my pages' master page whose value is daa.ConnectionString (daa is constructed in the PageLoad of master page).
Yet, when I navigate to the page that contains the above, declared datasource, I get a error that the database ("Standards") is offline. The StandardsTest1 db - the one I want to use as the alternate - is online.
the revelant section of my web config looks like this (user names and pwds are hidden):
<configuration>
<configSections>
<section name="SqlServerCatalogNameOverwrites" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<SqlServerCatalogNameOverwrites>
<add key="StandardsTest1" value="Standards" />
</SqlServerCatalogNameOverwrites>
<appSettings>
<!-- Connection String used by llblGen -->
<!-- <add key="Main.ConnectionString" value="data source=COMPAQ-EVO;initial catalog=Standards;User ID=********;Password=********;persist security info=False;packet size=4096"/> -->
<add key="Main.ConnectionString" value="data source=COMPAQ-EVO;initial catalog=StandardsTest1;User ID=********;Password=*********;persist security info=False;packet size=4096"/>
I have no other connection string declared in the web.config below those shown above.
Help! I've got llblgendatasource2 controls declared everywhere and I need to test my app with an alternate database.
Here's the exception stack:
Database 'Standards' cannot be opened because it is offline.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Database 'Standards' cannot be opened because it is offline.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Database 'Standards' cannot be opened because it is offline.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857306
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734918
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +31
System.Data.SqlClient.SqlDataReader.get_MetaData() +62
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +886
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +7
SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) +253
[ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: Database 'Standards' cannot be opened because it is offline.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.]
SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.Execute(CommandBehavior behavior) +406
SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFactory2 entityFactory, IEntityCollection2 collectionToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, Boolean allowDuplicates, IEntityFields2 fieldsUsedForQuery) +632
SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, Int32 pageNumber, Int32 pageSize) +822
SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath) +145
SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, Int32 pageNumber, Int32 pageSize) +112
SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView2.ExecuteSelectEntityCollection(Int32 pageSize, Int32 pageNumber, DataSourceSelectArguments arguments) +650
SD.LLBLGen.Pro.ORMSupportClasses.LLBLGenProDataSourceView2.ExecuteSelect(DataSourceSelectArguments arguments) +289
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
System.Web.UI.WebControls.FormView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.FormView.EnsureDataBound() +163
System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +41
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360
Joined: 22-Mar-2006
With what databasename was your LLBLGen project compiled ?
<configuration>
<configSections>
<section name="SqlServerCatalogNameOverwrites" type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<SqlServerCatalogNameOverwrites>
<add key="StandardsTest1" value="Standards" />
</SqlServerCatalogNameOverwrites>
<appSettings>
<!-- Connection String used by llblGen -->
<!-- <add key="Main.ConnectionString" value="data source=COMPAQ-EVO;initial catalog=Standards;User ID=********;Password=********;persist security info=False;packet size=4096"/> -->
<add key="Main.ConnectionString" value="data source=COMPAQ-EVO;initial catalog=StandardsTest1;User ID=********;Password=*********;persist security info=False;packet size=4096"/>
The SqlServerCatalogNameOverwrites Key should be the name of the compiled-with database, so I think that should be Standards by default ; then both the value and the connectionstring should be set to the alternate database, StandardsTest1 in your case. This has to work just fine in adapter mode.
What also strikes me as odd is the error message produced by your SQL Server. When a wrong connectionstring is defined, the server answers with a whole different message in my case :
System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
When the database really is offline then it says so by showing this message :
System.Data.SqlClient.SqlException: Cannot open database requested in login 'DbTest'. Login fails.
So that's a bit strange....
1) it has nothing to do with the datasourcecontrol, it should also happen with a normal fetch of 1 entity for example 2) please enable DQE tracing and check what the queries are that are generated.
Joined: 13-Jan-2006
OK. Enabled DQE tracing and got this:
The thread 0x234 has exited with code 0 (0x0).
The thread 0x10c8 has exited with code 0 (0x0).
A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.dll
Method Enter: CollectionCore.Clear
Method Exit: CollectionCore.Clear
Method Enter: DataAccessAdapterBase.OpenConnection
: New connection created.
: Connection physically opened.
Method Exit: DataAccessAdapterBase.OpenConnection
Method Enter: DataAccessAdapterBase.FetchEntityCollection(7)
Method Enter: DataAccessAdapterBase.FetchEntityCollection(5)
Method Enter: DataAccessAdapterBase.FetchEntityCollectionInternal(6)
Active Entity Collection Description:
EntityCollection: SD.LLBLGen.Pro.ORMSupportClasses.EntityCollectionNonGeneric. Will contain entities of type: OrganizationEntity
'WebDev.WebServer.EXE' (Managed): Loaded 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\admin\deefa5f8\3ffa0815\assembly\dl3\b5eec7a0\0034adb8_826ac701\SD.LLBLGen.Pro.DQE.SqlServer.NET20.DLL', No symbols loaded.
Method Enter: CreatePagingSelectDQ
Method Enter: CreateSelectDQ
Method Enter: CreateSelectDQ
Generated Sql query:
Query: SELECT [Standards].[dbo].[Organization].[ID] AS [Id], [Standards].[dbo].[Organization].[Name_e] AS [NameE], [Standards].[dbo].[Organization].[Name_f] AS [NameF], [Standards].[dbo].[Organization].[Parent_ID] AS [ParentId], [Standards].[dbo].[Organization].[Tree_Level] AS [TreeLevel], [Standards].[dbo].[Organization].[PreOrder], [Standards].[dbo].[Organization].[PostOrder], [Standards].[dbo].[Organization].[About_Heading_e] AS [AboutHeadingE], [Standards].[dbo].[Organization].[About_Heading_f] AS [AboutHeadingF], [Standards].[dbo].[Organization].[About_Us_e] AS [AboutUsE], [Standards].[dbo].[Organization].[About_Us_f] AS [AboutUsF], [Standards].[dbo].[Organization].[Include_Activities] AS [IncludeActivities], [Standards].[dbo].[Organization].[Activities_Heading_e] AS [ActivitiesHeadingE], [Standards].[dbo].[Organization].[Activities_Heading_f] AS [ActivitiesHeadingF], [Standards].[dbo].[Organization].[Activities_Text_e] AS [ActivitiesTextE], [Standards].[dbo].[Organization].[Activities_Text_f] AS [ActivitiesTextF], [Standards].[dbo].[Organization].[Include_Groups] AS [IncludeGroups], [Standards].[dbo].[Organization].[Groups_Heading_e] AS [GroupsHeadingE], [Standards].[dbo].[Organization].[Groups_Heading_f] AS [GroupsHeadingF], [Standards].[dbo].[Organization].[Group_Text_e] AS [GroupTextE], [Standards].[dbo].[Organization].[Group_Text_f] AS [GroupTextF], [Standards].[dbo].[Organization].[Include_Drafts_Issues] AS [IncludeDraftsIssues], [Standards].[dbo].[Organization].[Drafts_Issues_Heading_e] AS [DraftsIssuesHeadingE], [Standards].[dbo].[Organization].[Drafts_Issues_Heading_f] AS [DraftsIssuesHeadingF], [Standards].[dbo].[Organization].[Documents_e] AS [DocumentsE], [Standards].[dbo].[Organization].[Documents_f] AS [DocumentsF], [Standards].[dbo].[Organization].[Include_Bottom] AS [IncludeBottom], [Standards].[dbo].[Organization].[Bottom_Heading_e] AS [BottomHeadingE], [Standards].[dbo].[Organization].[Bottom_Heading_f] AS [BottomHeadingF], [Standards].[dbo].[Organization].[Bottom_e] AS [BottomE], [Standards].[dbo].[Organization].[Bottom_f] AS [BottomF], [Standards].[dbo].[Organization].[Date_Created] AS [DateCreated], [Standards].[dbo].[Organization].[Date_Published] AS [DatePublished], [Standards].[dbo].[Organization].[Last_Updated] AS [LastUpdated], [Standards].[dbo].[Organization].[Date_Reviewed] AS [DateReviewed] FROM [Standards].[dbo].[Organization] WHERE ( ( ( [Standards].[dbo].[Organization].[ID] = @Id1)))
Parameter: @Id1 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 4.
Method Exit: CreateSelectDQ
Method Exit: CreatePagingSelectDQ: no paging.
Method Enter: DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery
Method Enter: DataAccessAdapterBase.OpenConnection
Method Exit: DataAccessAdapterBase.OpenConnection
Executed Sql Query:
Query: SELECT [Standards].[dbo].[Organization].[ID] AS [Id], [Standards].[dbo].[Organization].[Name_e] AS [NameE], [Standards].[dbo].[Organization].[Name_f] AS [NameF], [Standards].[dbo].[Organization].[Parent_ID] AS [ParentId], [Standards].[dbo].[Organization].[Tree_Level] AS [TreeLevel], [Standards].[dbo].[Organization].[PreOrder], [Standards].[dbo].[Organization].[PostOrder], [Standards].[dbo].[Organization].[About_Heading_e] AS [AboutHeadingE], [Standards].[dbo].[Organization].[About_Heading_f] AS [AboutHeadingF], [Standards].[dbo].[Organization].[About_Us_e] AS [AboutUsE], [Standards].[dbo].[Organization].[About_Us_f] AS [AboutUsF], [Standards].[dbo].[Organization].[Include_Activities] AS [IncludeActivities], [Standards].[dbo].[Organization].[Activities_Heading_e] AS [ActivitiesHeadingE], [Standards].[dbo].[Organization].[Activities_Heading_f] AS [ActivitiesHeadingF], [Standards].[dbo].[Organization].[Activities_Text_e] AS [ActivitiesTextE], [Standards].[dbo].[Organization].[Activities_Text_f] AS [ActivitiesTextF], [Standards].[dbo].[Organization].[Include_Groups] AS [IncludeGroups], [Standards].[dbo].[Organization].[Groups_Heading_e] AS [GroupsHeadingE], [Standards].[dbo].[Organization].[Groups_Heading_f] AS [GroupsHeadingF], [Standards].[dbo].[Organization].[Group_Text_e] AS [GroupTextE], [Standards].[dbo].[Organization].[Group_Text_f] AS [GroupTextF], [Standards].[dbo].[Organization].[Include_Drafts_Issues] AS [IncludeDraftsIssues], [Standards].[dbo].[Organization].[Drafts_Issues_Heading_e] AS [DraftsIssuesHeadingE], [Standards].[dbo].[Organization].[Drafts_Issues_Heading_f] AS [DraftsIssuesHeadingF], [Standards].[dbo].[Organization].[Documents_e] AS [DocumentsE], [Standards].[dbo].[Organization].[Documents_f] AS [DocumentsF], [Standards].[dbo].[Organization].[Include_Bottom] AS [IncludeBottom], [Standards].[dbo].[Organization].[Bottom_Heading_e] AS [BottomHeadingE], [Standards].[dbo].[Organization].[Bottom_Heading_f] AS [BottomHeadingF], [Standards].[dbo].[Organization].[Bottom_e] AS [BottomE], [Standards].[dbo].[Organization].[Bottom_f] AS [BottomF], [Standards].[dbo].[Organization].[Date_Created] AS [DateCreated], [Standards].[dbo].[Organization].[Date_Published] AS [DatePublished], [Standards].[dbo].[Organization].[Last_Updated] AS [LastUpdated], [Standards].[dbo].[Organization].[Date_Reviewed] AS [DateReviewed] FROM [Standards].[dbo].[Organization] WHERE ( ( ( [Standards].[dbo].[Organization].[ID] = @Id1)))
Parameter: @Id1 : Int32. Length: 0. Precision: 10. Scale: 0. Direction: Input. Value: 4.
Method Enter: CollectionCore.PerformAdd
Entity to Add Description:
Entity: Standards.EntityClasses.OrganizationEntity. ObjectID: 75253c02-146f-4d18-ab12-97c2eae4dd40
PrimaryKey field: Id. Type: System.Int32. Value: 4
Index of added entity: 0
Method Exit: CollectionCore.PerformAdd
Method Exit: DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery
Method Exit: DataAccessAdapterBase.FetchEntityCollectionInternal(6)
Method Exit: DataAccessAdapterBase.FetchEntityCollection(5)
Method Enter: DataAccessAdapterBase.CloseConnection
Method Exit: DataAccessAdapterBase.CloseConnection
Joined: 13-Jan-2006
Here is the web.config file (with SQL Server login information obscured).
Filename | File size | Added on | Approval |
---|---|---|---|
Web.Config | 4,045 | 12-Jun-2007 09:19.01 | Approved |
The web.Config file looks good.
It appears to me that the web application is not seeing the changes to the web.config What happens if you remove the connection string all together from the config file?
Try to do an IISReset, clean the Temporary ASP.NET Files and re-build your application.
Found it.
instead of: SqlServerCatalogNameOverwrites
use sqlServerCatalogNameOverwrites
XML, it's case sensitive..
I found this when I copied your section declaration into my test project which also uses name overwriting. It then yelled it ran into an unknown section 'sqlServerCatalogNameOverwrites', which was the one I was been using all along. So then I saw the casing error.