Multiple DBs with Data Access Application Block

G

Guest

Using the June 2005 version of the Data Access Application Block of the
Enterprise Library at
http://msdn.microsoft.com/practices/AppBlocks/default.aspx?pull=/library/en-us/dnpag2/html/daab.asp


I have a Web.config and dataConfiguration.config as listed at the end of
this post. How could I get the CreateDatabase, etc. to behave such that it
checks machine.Substring(0,4) to see if it is a dev, prd (production) or uat
server and use the correct DB (without modifying the source code for the
Microsoft Data Access ELAB)?

<!--------START OF WEB.CONFIG------------------------!>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="enterpriselibrary.configurationSettings"
type="Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationManagerSectionHandler,
Microsoft.Practices.EnterpriseLibrary.Configuration, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null" />
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<!-- Define some output appenders -->
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<level value="DEBUG" />
<layout type="log4net.Layout.PatternLayout" value="%date [%thread]
%-5level %logger - %message%newline" />
</appender>
<appender name="LogFileAppender" type="log4net.Appender.FileAppender">
<level value="DEBUG" />
<file value="c:\\dev\\log4NetGTSMc.log" />
<appendToFile value="true" />
<!-- An alternate output encoding can be specified -->
<!-- <encoding value="unicodeFFFE" /> -->
<layout type="log4net.Layout.PatternLayout">
<geader value="[Header]
" />
<footer value="[Footer]
" />
<conversionPattern value="%date [%thread] %-5level %logger [%ndc]
<%property{auth}> - %message%newline" />
</layout>
<!-- Alternate layout using XML
<layout type="log4net.Layout.XMLLayout" /> -->
</appender>
<!-- Setup the root category, add the appenders and set the default
level -->
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
<system.web>
<!-- DYNAMIC DEBUG COMPILATION
Set compilation debug="true" to enable ASPX debugging. Otherwise,
setting this value to
false will improve runtime performance of this application.
Set compilation debug="true" to insert debugging symbols (.pdb
information)
into the compiled page. Because this creates a larger file that
executes
more slowly, you should set this value to true only when debugging
and to
false at all other times. For more information, refer to the
documentation about
debugging ASP .NET files.
-->
<compilation defaultLanguage="c#" debug="true" />
<!-- CUSTOM ERROR MESSAGES
Set customError mode values to control the display of user-friendly
error messages to users instead of error details (including a
stack trace):

"On" Always display custom (friendly) messages
"Off" Always display detailed ASP.NET error information.
"RemoteOnly" Display custom (friendly) messages only to users not
running
on the local Web server. This setting is recommended for security
purposes, so
that you do not display application detail information to remote
clients.
-->
<customErrors mode="Off" />
<!-- AUTHENTICATION
This section sets the authentication policies of the application.
Possible modes are "Windows", "Forms",
"Passport" and "None"
-->
<authentication mode="Windows" />
<identity impersonate="true"/>
<!-- APPLICATION-LEVEL TRACE LOGGING
Application-level tracing enables trace log output for every page
within an application.
Set trace enabled="true" to enable application trace logging. If
pageOutput="true", the
trace information will be displayed at the bottom of each page.
Otherwise, you can view the
application trace log by browsing the "trace.axd" page from your
web application
root.
-->
<trace enabled="false" requestLimit="10" pageOutput="false"
traceMode="SortByTime" localOnly="true" />
<!-- SESSION STATE SETTINGS
By default ASP .NET uses cookies to identify which requests belong
to a particular session.
If cookies are not available, a session can be tracked by adding a
session identifier to the URL.
To disable cookies, set sessionState cookieless="true".
-->
<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data
source=127.0.0.1;user id=sa;password=" cookieless="false" timeout="20" />
<!-- GLOBALIZATION
This section sets the globalization settings of the application.
-->
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myTextListener"
type="System.Diagnostics.TextWriterTraceListener,System, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089,
initializeData=c:\dev\test.log" />
</listeners>
</trace>
</system.diagnostics>
<enterpriselibrary.configurationSettings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
applicationName="Application"
xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/configuration">
<configurationSections>
<configurationSection xsi:type="ReadOnlyConfigurationSectionData"
name="dataConfiguration" encrypt="false">
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File
Storage Provider" path="dataConfiguration.config" />
<dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml
Serializer Transformer">
<includeTypes />
</dataTransformer>
</configurationSection>
</configurationSections>
<keyAlgorithmStorageProvider xsi:nil="true" />
<includeTypes />
</enterpriselibrary.configurationSettings>
</configuration>
<!--------END OF WEB.CONFIG------------------------!>

<!--------START OF DATACONFIGURATION.CONFIG------------------------!>
<?xml version="1.0" encoding="utf-8"?>
<dataConfiguration>
<xmlSerializerSection
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.1.0.0, Culture=neutral,
PublicKeyToken=null">
<enterpriseLibrary.databaseSettings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultInstance="GTSM"
xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">
<databaseTypes>
<databaseType name="Sql Server"
type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" />
</databaseTypes>
<instances>
<instance name="aqqa" type="Sql Server" connectionString="Sql
Connection String" />
</instances>
<connectionStrings>
<connectionString name="Sql Connection String">
<parameters>
<parameter name="database" value="aqqa" isSensitive="false" />
<parameter name="Integrated Security" value="True"
isSensitive="true" />
<parameter name="server" value="devSrv19182" isSensitive="false"
/>
</parameters>
</connectionString>
</connectionStrings>
</enterpriseLibrary.databaseSettings>
</xmlSerializerSection>
</dataConfiguration>
<!--------END OF DATACONFIGURATION.CONFIG------------------------!>
 
K

Kevin Yu [MSFT]

Hi Patrick,

In this case, I suggest you write a method that checks for the substring
and return the instance string as you need to CreateDatabase and other
methods as argument. So you have to call this specific method manually
before the methods are called.

Alternatively, you can inherit from the Enterprise Library classes and call
the string processing method in the override methods.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

Kevin,

I have a similar issue that I am trying to tackle. After searching the
forums, I came across this thread. I am not sure I completely understand
your reply. Can you please elaborate a bit on what needs to be done in order
to accomplish the use of multiple DBs using the Data Access Block. If
possible, can you provide with some example code.

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top