OleDbConnection syntax error

Discussion in 'ASP .Net' started by msch-prv@bluewin.ch, Jul 19, 2006.

  1. Guest

    I'm having a format error with OleDbConnection (Format of the
    initialization string does not conform to specification starting at
    index 0) with the following. (The line referred to by the compiler isI
    flagged with: <-- problem) . I use ASP.NET 2.0.

    TIA for any hints, Mark

    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>

    Dim objDataSet As New DataSet()
    Dim objDataAdapter As New OleDbDataAdapter()
    Dim strConnection As String =
    ConfigurationManager.ConnectionStrings("DbConn").ConnectionString

    Dim objConnection As New OleDbConnection(strConnection) <-- format
    error

    objConnection.Open()
    Dim objCommand As New OleDbCommand(strSQL, objConnection)
    objDataAdapter.SelectCommand = objCommand
    objDataAdapter.Fill(objDataSet)

    grd2.DataSource = objDataAdapter.SelectCommand
    grd2.DataBind()

    where (web.config):
    <connectionStrings>
    <add name="DbConn"
    connectionString="~/App_Data/CRM2K_be.mdb"
    providerName="System.Data.OleDb"/>
    </connectionStrings>
     
    , Jul 19, 2006
    #1
    1. Advertising

  2. Guest

    I found a workaround, but this is contrary to the samples I have seen
    so far.

    The following works:

    Dim objConnection As New
    OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
    & "DATA SOURCE=" &
    Server.MapPath("App_Data/CRM2K_be.mdb;"))

    However, with DbConn defined in web.config as above yields an error::

    Dim strConn As String =
    ConfigurationManager.ConnectionStrings("DbConn").ConnectionString
    Dim objConnection As New OleDbConnection(strConn)

    fails presumably because it returns a fraction of the connection
    string, since:

    Response.Write(strConn) = '~/App_Data/CRM2K_be.mdb'

    What is the correct syntax for web.config declarations? TIA, Mark
     
    , Jul 19, 2006
    #2
    1. Advertising

  3. I believe the correct connection string should be:

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;"

    Additionally, the "~" is not understood by OleDB because it's a server
    construct for ASP.NET.

    Hope this works!
    --
    Christopher A. Reed
    "The oxen are slow, but the earth is patient."

    <> wrote in message
    news:...
    > I'm having a format error with OleDbConnection (Format of the
    > initialization string does not conform to specification starting at
    > index 0) with the following. (The line referred to by the compiler isI
    > flagged with: <-- problem) . I use ASP.NET 2.0.
    >
    > TIA for any hints, Mark
    >
    > <%@ Import Namespace="System.Data" %>
    > <%@ Import Namespace="System.Data.OleDb" %>
    >
    > Dim objDataSet As New DataSet()
    > Dim objDataAdapter As New OleDbDataAdapter()
    > Dim strConnection As String =
    > ConfigurationManager.ConnectionStrings("DbConn").ConnectionString
    >
    > Dim objConnection As New OleDbConnection(strConnection) <-- format
    > error
    >
    > objConnection.Open()
    > Dim objCommand As New OleDbCommand(strSQL, objConnection)
    > objDataAdapter.SelectCommand = objCommand
    > objDataAdapter.Fill(objDataSet)
    >
    > grd2.DataSource = objDataAdapter.SelectCommand
    > grd2.DataBind()
    >
    > where (web.config):
    > <connectionStrings>
    > <add name="DbConn"
    > connectionString="~/App_Data/CRM2K_be.mdb"
    > providerName="System.Data.OleDb"/>
    > </connectionStrings>
    >
     
    Christopher Reed, Jul 19, 2006
    #3
  4. Guest

    Thanks Christopher,

    It works now after editing the connection strings in web.config:

    <connectionStrings>
    <add name="DbConn"
    connectionString="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
    SOURCE=|DataDirectory|\CRM2K_be.md"
    providerName="System.Data.OleDb"/>
    </connectionStrings>
     
    , Jul 19, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vMike

    Re: ASP.NET and OleDbConnection

    vMike, Jun 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,345
    vMike
    Jun 24, 2003
  2. vMike

    Re: ASP.NET and OleDbConnection

    vMike, Jun 24, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    2,285
    rajeshseetharam
    Jun 6, 2005
  3. Roger Cantillo

    oleDBConnection not recognizing Database

    Roger Cantillo, Aug 28, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    3,090
    Kevin Spencer
    Aug 28, 2003
  4. Daniel Conlon

    OleDbConnection Security Exception

    Daniel Conlon, Oct 20, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    975
    Wim Hollebrandse
    Oct 20, 2003
  5. Keith
    Replies:
    1
    Views:
    480
    alex bowers
    Dec 11, 2003
Loading...

Share This Page