Community discussion forum

Connection String format between ADO and ADO.NET

  • 3 years ago

    Hi Folks!


    I've written a .NET assembly (named TaxComponent) to be used as COM component with existing ASP app (named PrintShop). I've defined a property in TaxComponent to hold connection string. Of course I'm using ADO.NET in my assembly and its ADO in existing ASP app. Now when I try to pass the connection string property being used in ASP app to my .NET based COM, it errors out saying :


    System.ArgumentException: Keyword not supported: 'driver'. at System.Data.Common.DbConnectionOptions


    The Connection string in Printshop looks like:
    Application("ConnectString") = "Driver={SQL Server};Server=..."


    Is there an easy way to strip off this extra "Driver = ..." part from connection string or I'll have to do some string manipulation in my TaxComponent to remove this not required clause?


    I'm guessing since I've:
    using System.Data.SqlClient;
    in my TaxComponent, it already knows its SQL server (and hence does not need the "Driver = ..." directive), but I'd expect it to discard it silently.


    Any comments welcome!


    Thanks
    Sukhjinder

  • 3 years ago

    Well for now I've learned to live with a function like the one given below which takes as arguments connection string and the clause to remove and rips out the "Driver = .. " type of clause from it where ever it appears in the connection string:
    private string CleanStringOneofSecond(string OriginalConn, string tobeRemoved)
           {
               string Result;
               if ((OriginalConn.ToUpper()).Contains(tobeRemoved.ToUpper()))
               {
                   int PosToBeRemoved = (OriginalConn.ToUpper()).IndexOf(tobeRemoved.ToUpper());
                   int PosToBeRemovedColon = OriginalConn.IndexOf(";", PosToBeRemoved);
                   if (PosToBeRemovedColon > 1) //tobeRemoved String is not in the end
                   {
                       Result = OriginalConn.Remove(PosToBeRemoved, PosToBeRemovedColon - PosToBeRemoved + 1);
                       return Result;
                   }
                   else //tobeRemoved String is in the end (and hence may not have ending semi-colon)
                   {
                       Result = OriginalConn.Remove(PosToBeRemoved - 1, OriginalConn.Length - PosToBeRemoved);
                       return Result;
                   }
               }
               else
               {
                   Result = OriginalConn;
                   return Result;
               }
           }
    But would welcome a more graceful way out

  • 5 months ago

    http://bit.ly/izsu9 The new VSTS enables you to convert your imagination into the perfect material images on screen ! Let your mind do the thinking and VSTS will do the rest

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback