locked
how can i use DatabaseFactory.CreateDatabase()? RRS feed

  • Question

  • User-115257982 posted

    how can i use this?

    Database _dbBase = DatabaseFactory.CreateDatabase(); 

    when i use this code...im getting this error

    The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Data.Database, null]) failed: The value can not be null or an empty string. (Strategy type ConfiguredObjectStrategy, index 2)

     

    Thursday, September 9, 2010 10:39 AM

Answers

  • User1105131773 posted

    Have you got the required entries in your configuration file? I think you need something in configSections 

    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

    And a config section pointing to the connection string you have defined in your connection strings section

    <dataConfiguration defaultDatabase="Connection String" />

     <connectionStrings>
        <add name="Connection String" connectionString="server=(local);database=CMS;user=CMSUser;password=R1d1culus" providerName="System.Data.SqlClient" />
        <add name="Secure" connectionString="data source=(local);database=Settings;user=intranetuser;password=G1golfbreaks;application name={0};Connection Reset=false" providerName="System.Data.SqlClient" />
        <add name="Tracking" connectionString="server=(local);database=tracking;user=CMSUser;password=R1d1culus" providerName="System.Data.SqlClient" />
      </connectionStrings>

     <connectionStrings>

        <add name="Connection String" connectionString="server=(local);database=myDatabase;user=xxx;password=xxxxx" providerName="System.Data.SqlClient" />

      </connectionStrings>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 9, 2010 11:57 AM

All replies

  • User1105131773 posted

    Have you got the required entries in your configuration file? I think you need something in configSections 

    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

    And a config section pointing to the connection string you have defined in your connection strings section

    <dataConfiguration defaultDatabase="Connection String" />

     <connectionStrings>
        <add name="Connection String" connectionString="server=(local);database=CMS;user=CMSUser;password=R1d1culus" providerName="System.Data.SqlClient" />
        <add name="Secure" connectionString="data source=(local);database=Settings;user=intranetuser;password=G1golfbreaks;application name={0};Connection Reset=false" providerName="System.Data.SqlClient" />
        <add name="Tracking" connectionString="server=(local);database=tracking;user=CMSUser;password=R1d1culus" providerName="System.Data.SqlClient" />
      </connectionStrings>

     <connectionStrings>

        <add name="Connection String" connectionString="server=(local);database=myDatabase;user=xxx;password=xxxxx" providerName="System.Data.SqlClient" />

      </connectionStrings>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 9, 2010 11:57 AM
  • User-115257982 posted

    Hi simon.hatchard

    thanks for ur reply...

    now im able to conncet to my database with the Enterprise library...

    Im using the Exception Block to log the exception...when i use the sql Database the exception is logging to the database but not for the

    oracle....here is my code...if any mistakes please correct me.

     

    <?xml version="1.0"?>
    <!--
        Note: As an alternative to hand editing this file you can use the
        web admin tool to configure settings for your application. Use
        the Website->Asp.Net Configuration option in Visual Studio.
        A full list of settings and comments can be found in
        machine.config.comments usually located in
        \Windows\Microsoft.Net\Framework\v2.x\Config
    -->
    <configuration>
      <configSections>
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
            <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
              <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
              <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
              <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
              <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
            </sectionGroup>
          </sectionGroup>
        </sectionGroup>
      </configSections>
      <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
        defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
        <listeners>
          <add databaseInstanceName="eHMSConnectionString" writeLogStoredProcName="writeerrorlog"
            addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            traceOutputOptions="ThreadId" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Database Trace Listener" />
        </listeners>
        <formatters>
          <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
            type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Text Formatter" />
        </formatters>
        <categorySources>
          <add switchValue="All" name="General">
            <listeners>
              <add name="Database Trace Listener" />
            </listeners>
          </add>
        </categorySources>
        <specialSources>
          <allEvents switchValue="All" name="All Events" />
          <notProcessed switchValue="All" name="Unprocessed Category" />
          <errors switchValue="All" name="Logging Errors &amp; Warnings">
            <listeners>
              <add name="Database Trace Listener" />
            </listeners>
          </errors>
        </specialSources>
      </loggingConfiguration>
      <exceptionHandling>
        <exceptionPolicies>
          <add name="Exception Policy">
            <exceptionTypes>
              <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                postHandlingAction="NotifyRethrow" name="Exception">
                <exceptionHandlers>
                  <add logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                    formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    name="Logging Handler" />
                </exceptionHandlers>
              </add>
            </exceptionTypes>
          </add>
        </exceptionPolicies>
      </exceptionHandling>
      <dataConfiguration defaultDatabase="eHMSConnectionString" />
      <connectionStrings>
        <add name="eHMSConnectionString" connectionString="server=192.168.1.99;user id=XXX;password=XXX;data source=db"
          providerName="System.Data.OracleClient" />
      </connectionStrings>
      <appSettings />
      <system.web>
        <!--
                Set compilation debug="true" to insert debugging
                symbols into the compiled page. Because this
                affects performance, set this value to true only
                during development.
            -->
        <compilation debug="true">
          <assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
          </assemblies>
        </compilation>
        <!--
                The <authentication> section enables configuration
                of the security authentication mode used by
                ASP.NET to identify an incoming user.
            -->
        <authentication mode="Windows" />
        <!--
                The <customErrors> section enables configuration
                of what to do if/when an unhandled error occurs
                during the execution of a request. Specifically,
                it enables developers to configure html error pages
                to be displayed in place of a error stack trace.

            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm" />
                <error statusCode="404" redirect="FileNotFound.htm" />
            </customErrors>
            -->
        <pages>
          <controls>
            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          </controls>
        </pages>
        <httpHandlers>
          <remove verb="*" path="*.asmx" />
          <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />
        </httpHandlers>
        <httpModules>
          <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        </httpModules>
      </system.web>
      <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <providerOption name="CompilerVersion" value="v3.5" />
            <providerOption name="WarnAsError" value="false" />
          </compiler>
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <providerOption name="CompilerVersion" value="v3.5" />
            <providerOption name="OptionInfer" value="true" />
            <providerOption name="WarnAsError" value="false" />
          </compiler>
        </compilers>
      </system.codedom>
      <!--
            The system.webServer section is required for running ASP.NET AJAX under Internet
            Information Services 7.0.  It is not necessary for previous version of IIS.
        -->
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <modules>
          <remove name="ScriptModule" />
          <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        </modules>
        <handlers>
          <remove name="WebServiceHandlerFactory-Integrated" />
          <remove name="ScriptHandlerFactory" />
          <remove name="ScriptHandlerFactoryAppServices" />
          <remove name="ScriptResource" />
          <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        </handlers>
      </system.webServer>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>

    here is my oracle procedure....

     

    CREATE  PROCEDURE WriteErrorLog   
    (   
     @EventID int,    
     @Priority int,    
     @Severity nvarchar(32),    
     @Title nvarchar(256),    
     @Timestamp datetime,   
     @MachineName nvarchar(32),    
     @AppDomainName nvarchar(512),   
     @ProcessID nvarchar(256),   
     @ProcessName nvarchar(512),   
     @ThreadName nvarchar(512),   
     @Win32ThreadId nvarchar(128),   
     @Message nvarchar(1500),   
     @FormattedMessage ntext,   
     @LogId int OUTPUT   
    )   
    AS    
    BEGIN   
       
     INSERT INTO [Log] (   
      EventID,   
      Priority,   
      Severity,   
      Title,   
      [Timestamp],   
      MachineName,   
      AppDomainName,   
      ProcessID,   
      ProcessName,   
      ThreadName,   
      Win32ThreadId,   
      Message,   
      FormattedMessage   
     )   
     VALUES (   
      @EventID,    
      @Priority,    
      @Severity,    
      @Title,    
      @Timestamp,   
      @MachineName,    
      @AppDomainName,   
      @ProcessID,   
      @ProcessName,   
      @ThreadName,   
      @Win32ThreadId,   
      @Message,   
      @FormattedMessage)   
       
     SET @LogID = @@IDENTITY   
     RETURN @LogID   
       
    END

    GO

    CREATE  PROCEDURE AddCategory 
     -- Add the parameters for the function here 
     @CategoryName nvarchar(64), 
     @LogID int 
    AS 
    BEGIN 
     SET NOCOUNT ON; 
        DECLARE @CatID INT 
     SELECT @CatID = CategoryID FROM Category WHERE CategoryName = @CategoryName 
     IF @CatID IS NULL 
     BEGIN 
      INSERT INTO Category (CategoryName) VALUES(@CategoryName) 
      SELECT @CatID = @@IDENTITY 
     END 
     
     EXEC InsertCategoryLog @CatID, @LogID  
     
     RETURN @CatID 
    END

    GO

    CREATE PROCEDURE InsertCategoryLog 
     @CategoryID INT, 
     @LogID INT 
    AS 
    BEGIN 
     SET NOCOUNT ON; 
     
     DECLARE @CatLogID INT 
     SELECT @CatLogID FROM CategoryLog WHERE CategoryID=@CategoryID and LogID = @LogID 
     IF @CatLogID IS NULL 
     BEGIN 
      INSERT INTO CategoryLog (CategoryID, LogID) VALUES(@CategoryID, @LogID) 
      RETURN @@IDENTITY 
     END 
     ELSE RETURN @CatLogID 
    END

     please help me :-)

    Friday, September 10, 2010 7:14 AM