Enterprise Library Data Access Block 2.0
-
Hi guys, Please help,I am having an issue with data access block connection to the database from my class library project. using the data access block to connect to database works fine in my website project. but i try creating a separate class library project to connect to the database i now receive an error message. "The value can not be null or an empty string." and this is the code:
Database motomandb = DatabaseFactory.CreateDatabase(); DbCommand motomandbCommand = motomandb.GetSqlStringCommand(query); using(DbConnection motomanConnection = motomandb.CreateConnection()) { DbTransaction motomanTransaction = motomanConnection.BeginTransaction(); try { rowsaffected = motomandb.ExecuteNonQuery(motomandbCommand, motomanTransaction); motomanTransaction.Commit(); } catch (Exception e) { motomanTransaction.Rollback(); } }
thanks in advance -
Hi guys, Please help,I am having an issue with data access block connection to the database from my class library project. using the data access block to connect to database works fine in my website project. but i try creating a separate class library project to connect to the database i now receive an error message. "The value can not be null or an empty string." and this is the code:
Database motomandb = DatabaseFactory.CreateDatabase(); DbCommand motomandbCommand = motomandb.GetSqlStringCommand(query); using(DbConnection motomanConnection = motomandb.CreateConnection()) { DbTransaction motomanTransaction = motomanConnection.BeginTransaction(); try { rowsaffected = motomandb.ExecuteNonQuery(motomandbCommand, motomanTransaction); motomanTransaction.Commit(); } catch (Exception e) { motomanTransaction.Rollback(); } }
thanks in advancesaltcode wrote:
i now receive an error message. "The value can not be null or an empty string."
Where? I'm guessing that it is having problems with the cofiguration file, but without knowing where the error occured it may be somewhere else.
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
-
saltcode wrote:
i now receive an error message. "The value can not be null or an empty string."
Where? I'm guessing that it is having problems with the cofiguration file, but without knowing where the error occured it may be somewhere else.
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
-
the error occurred here. Database motomandb = DatabaseFactory.CreateDatabase(); i don't think is the configuration file bcos i connected to the database normally from the web project appcode folder.
saltcode wrote:
i don't think is the configuration file bcos i connected to the database normally from the web project appcode folder.
You've just extracted this out into its own class library and you are still running it as a web application? Is that right? Have you tried stepping into the Enterprise Library code and seeing where it's failing in there? Actually, it should tell you in the stack trace for the exception exactly where in the Enterprise Library it failed. Can you copy and paste the stack trace here?
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
-
saltcode wrote:
i don't think is the configuration file bcos i connected to the database normally from the web project appcode folder.
You've just extracted this out into its own class library and you are still running it as a web application? Is that right? Have you tried stepping into the Enterprise Library code and seeing where it's failing in there? Actually, it should tell you in the stack trace for the exception exactly where in the Enterprise Library it failed. Can you copy and paste the stack trace here?
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website
thanks for your time. here is the trace.
System.Configuration.ConfigurationErrorsException was unhandled by user code Message="The type Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null from configuration could not be created. (c:\\inetpub\\wwwroot\\motoman\\web.config line 57)" Source="System.Configuration" BareMessage="The type Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null from configuration could not be created." Filename="c:\\inetpub\\wwwroot\\motoman\\web.config" Line=57 StackTrace: at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSourceImplementation.GetSection(String sectionName) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource.GetSection(String sectionName) at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings.GetExceptionHandlingSettings(IConfigurationSource configurationSource) at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingConfigurationView.get_ExceptionHandlingSettings() at Microsoft.Practices.Enterprise
-
thanks for your time. here is the trace.
System.Configuration.ConfigurationErrorsException was unhandled by user code Message="The type Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null from configuration could not be created. (c:\\inetpub\\wwwroot\\motoman\\web.config line 57)" Source="System.Configuration" BareMessage="The type Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null from configuration could not be created." Filename="c:\\inetpub\\wwwroot\\motoman\\web.config" Line=57 StackTrace: at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult) at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission) at System.Configuration.BaseConfigurationRecord.GetSection(String configKey) at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey) at System.Configuration.ConfigurationManager.GetSection(String sectionName) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSourceImplementation.GetSection(String sectionName) at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource.GetSection(String sectionName) at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings.GetExceptionHandlingSettings(IConfigurationSource configurationSource) at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingConfigurationView.get_ExceptionHandlingSettings() at Microsoft.Practices.Enterprise
Have you included all the relevant DLLs in the references section. Parts of the Enterprise library load dynamically, so Visual Studio is not completely aware of their necessity so it cannot warn you at compile time. You need the DLL that includs this class:
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler
The DLL you need is: Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll It can probably be found in the folder: C:\Program Files\Microsoft Enterprise Library January 2006\bin
Upcoming events: * Edinburgh: Web Security Conference Day for Windows Developers (12th April) * Glasgow: Introduction to AJAX (2nd May), SQL Server, Mock Objects My website