Quantcast
Channel: Oracle, MySQL, Sybase, Informix and other databases
Viewing all articles
Browse latest Browse all 1350

Custom IIS URL Rewrite Provider MySQL ODBC

$
0
0

Hi

I am trying to write a Custom Rewrite Provider that use ODBC rather than the SQLClient as we are using MySQL database server. I am following the tutorial here http://learn.iis.net/page.aspx/804/developing-a-custom-rewrite-provider-for-url-rewrite-module/

This is the error we are getting 

Error Summary

<div>
Error Summary

HTTP Error 500.50 - URL Rewrite Module Error.

System.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode) at System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle) at System.Data.Odbc.OdbcConnectionOpen..ctor(OdbcConnection outerConnection, OdbcConnectionString connectionOptions) at System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.Odbc.OdbcConnection.Open() at ODBCProvider.Rewrite(String value) at Microsoft.Web.Iis.Rewrite.RewriteProviderManager.InvokeProviderUnicode(String providerName, String providerInput)

</div>

This is the code for the provider

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Odbc;
using Microsoft.Web.Iis.Rewrite;


    public class ODBCProvider: IRewriteProvider, IProviderDescriptor
    {
        private string connectionString;
        private string storedProcedure;


        public void Initialize(IDictionary<string, string> settings, IRewriteContext rewriteContext)
        {
            if (!settings.TryGetValue("Connection", out connectionString) || string.IsNullOrEmpty(connectionString))
                throw new ArgumentException("ODBC Connection string is required and connot be empty");
            if (!settings.TryGetValue("Command", out storedProcedure) || string.IsNullOrEmpty(storedProcedure))
                throw new ArgumentException("ODBC Command string is required and connot be empty");
        }


        public string Rewrite(string value)
        {
            OdbcConnection dbcon = new OdbcConnection(connectionString);
            OdbcCommand dbcom = new OdbcCommand("CALL " + storedProcedure + "(?)", dbcon);
            dbcom.CommandType = System.Data.CommandType.StoredProcedure;
            dbcom.Parameters.AddWithValue("?", value);
            dbcon.Open();
            string url = (string)dbcom.ExecuteScalar();
            dbcon.Close();
            return url;
        }


        public IEnumerable<SettingDescriptor> GetSettings()
        {
            yield return new SettingDescriptor("Connection", "ODBC connection string");
            yield return new SettingDescriptor("Command", "ODBC stored procedure");
        }
    }


With the following settings in the web.config

<rule name="NavigationMappings" stopProcessing="true"><match url="(.*)" /><conditions><add input="{ODBCProvider:{R:1}}" pattern="(.+)" /></conditions><action type="Rewrite" url="{C:1}" /></rule><provider name="ODBCProvider" type="ODBCProvider, ODBCProvider, Version=1.0.3866.30779, Culture=neutral, PublicKeyToken=18cc6a842eca6b31"><settings><add key="Command" value="url_rewrite_navigation" /><add key="Connection" value="Driver={MySQL ODBC 5.1 Driver};Server=localhost;Port=3306;Database=decode_cms_dev4;User=user;Password=password;Option=3;" /></settings></provider>


I know the MySQL Driver is installed because we use it for the main connection for the rest of the website. So any ideas why this isnt working?

The computer testing this out is Windows 7 with IIS 7.5 x64

Thanks

Dan




Viewing all articles
Browse latest Browse all 1350

Trending Articles