471,350 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

A way to extend the Enterprise Library to work with other DB providers

Hi all.

I'm trying to extend the Microsoft Enterprise Library Data Access
Application Block
(http://msdn.microsoft.com/library/en...asp?frame=true)
to work with a Borland Interbase database.

To do this, I copied and renamed the source files for working with a SQL
Server database (SqlCommandWrapper.cs/SqlDatabase.cs to
InterbaseCommandWrapper.cs/InterbaseDatabase.cs). I then changed all
the type names to their corresponding Borland types. I then
successfully recompiled the assembly.

Next I used the Enterprise Library Configuration tool to produce the
app.config and dataConfiguration.config files with the correct
parameters to connect to my Interbase database (both files at the end of
this message).

I now try and connect to my database from a test application. The
problem is, before it even tries to connect, it gives the error:

An unhandled exception of type
'System.Configuration.ConfigurationException' occurred in
microsoft.practices.enterpriselibrary.configuratio n.dll

Additional information: The type
'Microsoft.Practices.EnterpriseLibrary.Data.Interb aseDatabase,
Microsoft.Practices.EnterpriseLibrary.Data' could not be loaded for the
'Database'.

In other words, it seems to be saying that the type
Microsoft.Practices.EnterpriseLibrary.Data.Interba seDatabase is not
defined in the assembly Microsoft.Practices.EnterpriseLibrary.Data. To
test this, I opened the dll with ildasm.exe. This shows that the type
DOES indeed exist. I'm at a loss at how to go any further with this and
would very appreciative of anyone who could tell me what's wrong. The
InterbaseDatabase.cs file is also at the end of this message if anyone
is interested.

By the way, if anyone else already has already tried to extend the
Enterprise Library to work with Interbase, then please let me know.

Thanks,

Mike


App.config
----------

<configuration>
<configSections>
<section name="enterpriselibrary.configurationSettings"
type="Microsoft.Practices.EnterpriseLibrary.Config uration.ConfigurationManagerSectionHandler,
Microsoft.Practices.EnterpriseLibrary.Configuratio n, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null" />
</configSections>
<enterpriselibrary.configurationSettings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
applicationName="TestProject"
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>

DataConfiguration.config
------------------------

<?xml version="1.0" encoding="utf-8"?>
<dataConfiguration>
<xmlSerializerSection
type="Microsoft.Practices.EnterpriseLibrary.Data.C onfiguration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.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="UWC"
xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">
<databaseTypes>
<databaseType name="Interbase"
type="Microsoft.Practices.EnterpriseLibrary.Data.I nterbaseDatabase,
Microsoft.Practices.EnterpriseLibrary.Data" />
</databaseTypes>
<instances>
<instance name="UWC" type="Interbase"
connectionString="Interbase Connection String" />
</instances>
<connectionStrings>
<connectionString name="Interbase Connection String">
<parameters>
<parameter name="Provider" value="interbase"
isSensitive="false" />
<parameter name="Assembly" value="Borland.Data.Interbase"
isSensitive="false" />
<parameter name="Culture" value="neutral"
isSensitive="false" />
<parameter name="Database"
value="dbserver:/opt/interbase/data/uwc.gdb" isSensitive="false" />
<parameter name="Password" value="cfwrip"
isSensitive="false" />
<parameter name="UserName" value="app" isSensitive="false" />
</parameters>
</connectionString>
</connectionStrings>
</enterpriseLibrary.databaseSettings>
</xmlSerializerSection>
</dataConfiguration>

InterbaseDatabase.cs
--------------------

//================================================== =============================
// Microsoft patterns & practices Enterprise Library
// Data Access Application Block
//================================================== =============================
// Copyright Microsoft Corporation. All rights reserved.
// Adapted from ACA.NET with permission from Avanade Inc.
// ACA.NET copyright Avanade Inc. All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//================================================== =============================

using System;
using System.Data;
using System.Data.Common;
using Borland.Data.Interbase;
using Borland.Data.Common;
using Borland.Data.Provider;

namespace Microsoft.Practices.EnterpriseLibrary.Data.Interba se
{
/// <summary>
/// <para>Represents an Interbase Database.</para>
/// </summary>
/// <remarks>
/// <para>
/// Internally uses the BDP Managed Provider from Borland to connect
to the database.
/// </para>
/// </remarks>
public class InterbaseDatabase : Database
{
/// <summary>
/// Default constructor
/// </summary>
public InterbaseDatabase() : base()
{
}

/// <summary>
/// <para>Gets the parameter token used to delimit parameters
for the Sql Database.</para>
/// </summary>
/// <value>
/// <para>The '' symbol.</para>
/// </value>
protected override char ParameterToken
{
get { return '@'; }
}

/// <summary>
/// <para>Get the connection for this database.</para>
/// <seealso cref="IDbConnection"/>
/// <seealso cref="BdpConnection"/>
/// </summary>
/// <returns>
/// <para>The <see cref="BdpConnection"/> for this database.</para>
/// </returns>
public override IDbConnection GetConnection()
{
return new BdpConnection(ConnectionString);
}

/// <summary>
/// <para>Create a <see cref="InterbaseCommandWrapper"/> for a
stored procedure.</para>
/// </summary>
/// <param name="storedProcedureName"><para>The name of the
stored procedure.</para></param>
/// <returns><para>The <see cref="InterbaseCommandWrapper"/>
for the stored procedure.</para></returns>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="storedProcedureName"/> can not be
<see langword="null"/> (Nothing in Visual Basic).</para>
/// </exception>
public override DBCommandWrapper
GetStoredProcCommandWrapper(string storedProcedureName)
{
if (storedProcedureName == null)
{
throw new ArgumentNullException("storedProcedureName");
}
if (storedProcedureName.Length == 0)
{
throw new ArgumentException("SQL command string not
supplied", "storedProcedureName");
}
return new InterbaseCommandWrapper(storedProcedureName,
CommandType.StoredProcedure, ParameterToken);
}

/// <summary>
/// <para>Create an <see cref="InterbaseCommandWrapper"/> for a
stored procedure.</para>
/// </summary>
/// <param name="storedProcedureName"><para>The name of the
stored procedure.</para></param>
/// <param name="parameterValues"><para>The list of parameters
for the procedure.</para></param>
/// <returns><para>The <see cref="InterbaseCommandWrapper"/>
for the stored procedure.</para></returns>
/// <remarks>
/// <para>The parameters for the stored procedure will be
discovered and the values are assigned in positional order.</para>
/// </remarks>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="storedProcedureName"/> can not be
<see langword="null"/> (Nothing in Visual Basic).</para>
/// <para>- or -</para>
/// <para><paramref name="parameterValues"/> can not be <see
langword="null"/> (Nothing in Visual Basic).</para>
/// </exception>
/// <exception cref="ArgumentException">
/// <para><paramref name="storedProcedureName"/> hast not been
initialized.</para>
/// </exception>
public override DBCommandWrapper
GetStoredProcCommandWrapper(string storedProcedureName, params object[]
parameterValues)
{
if (storedProcedureName == null)
{
throw new ArgumentNullException("storedProcedureName");
}
if (storedProcedureName.Length == 0)
{
throw new ArgumentException("SQL command string not
supplied", "storedProcedureName");
}
if (parameterValues == null)
{
throw new ArgumentNullException("parameterValues");
}
return new InterbaseCommandWrapper(storedProcedureName,
CommandType.StoredProcedure, ParameterToken, parameterValues);
}

/// <summary>
/// <para>Create an <see cref="InterbaseCommandWrapper"/> for a
SQL query.</para>
/// </summary>
/// <param name="query"><para>The text of the
query.</para></param>
/// <returns><para>The <see cref="InterbaseCommandWrapper"/>
for the SQL query.</para></returns>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="query"/> can not be <see
langword="null"/> (Nothing in Visual Basic).</para>
/// </exception>
/// <exception cref="ArgumentException">
/// <para><paramref name="query"/> hast not been
initialized.</para>
/// </exception>
public override DBCommandWrapper
GetSqlStringCommandWrapper(string query)
{
if (query == null)
{
throw new ArgumentNullException("query");
}
if (query.Length == 0)
{
throw new ArgumentException("SQL command string not
supplied", "query");
}
return new InterbaseCommandWrapper(query, CommandType.Text,
ParameterToken);
}

/// <summary>
/// <para>Create a <see cref="BdpDataAdapter"/> with the given
update behavior and connection.</para>
/// </summary>
/// <param name="updateBehavior">
/// <para>One of the <see cref="UpdateBehavior"/> values.</para>
/// </param>
/// <param name="connection">
/// <para>The open connection to the database.</para>
/// </param>
/// <returns>An <see cref="BdpDataAdapter"/>.</returns>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="connection"/> can not be <see
langword="null"/> (Nothing in Visual Basic).</para>
/// </exception>
protected override DbDataAdapter GetDataAdapter(UpdateBehavior
updateBehavior, IDbConnection connection)
{
string queryStringToBeFilledInLater = String.Empty;
BdpDataAdapter adapter = new
BdpDataAdapter(queryStringToBeFilledInLater, (BdpConnection)connection);

if (updateBehavior == UpdateBehavior.Continue)
{
adapter.RowUpdated += new
BdpRowUpdatedEventHandler(OnInterbaseRowUpdated);
}
return adapter;
}

/// <devdoc>
/// Listens for the RowUpdate event on a data adapter to
support UpdateBehavior.Continue
/// </devdoc>
private void OnInterbaseRowUpdated(object sender,
BdpRowUpdatedEventArgs rowThatCouldNotBeWritten)
{
// doesn't seem to be supported by the BDP
/*
if (rowThatCouldNotBeWritten.RecordsAffected == 0)
{
if (rowThatCouldNotBeWritten.Errors != null)
{
rowThatCouldNotBeWritten.Row.RowError =
SR.ErrorMessageUpdateDataSetRowFailure;
rowThatCouldNotBeWritten.Status =
UpdateStatus.SkipCurrentRow;
}
}*/
}
}
}
Jul 21 '05 #1
1 4160
Mike Chamberlain wrote:
Hi all.

I'm trying to extend the Microsoft Enterprise Library Data Access
Application Block
(http://msdn.microsoft.com/library/en...asp?frame=true)
to work with a Borland Interbase database.


No one have any thoughts on this?

Mike
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by ViperDK \(Daniel K.\) | last post: by
3 posts views Thread by veera sekhar kota | last post: by
2 posts views Thread by bjhogan | last post: by
reply views Thread by Roel | last post: by
7 posts views Thread by Bruce One | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.