473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

OleDbConnection syntax error

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").C onnectionString

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 '06 #1
3 3828
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").C onnectionString
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 '06 #2
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."

<ms******@bluewin.chwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
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").C onnectionString

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 '06 #3
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 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Job Lot | last post by:
I have written the following function which returns OleDbConnection object. If global variable g_strDbPath contains an invalid file name or path name the catch block throws an error with...
1
by: Lilly | last post by:
Hi all. I'm really sorry for this post, I'm sure most of you will think it's a silly question, but the following doesn't work and I'm really new to ASP.NET: <%@ Page Language="C#" %> <%@...
3
by: Shreeram Natarajan | last post by:
Hello, Iam developing a sharepoint webpart which needs to read data from an excel file. Iam using OleDbconnection for reading data from excel. However using OleDbconnection object gives the...
2
by: Grant | last post by:
My C# web application connects to an Access database using the OleDbConnection and OleDbDataReader. I have 3 other computers that connect to this server but very frequently I get an 'Unspecified...
0
by: CyberLotus | last post by:
Hi, I've created a web application and through this I want to import Excel data to database. Following is the code that I've written, ...
4
by: tamarindm | last post by:
I am using the following to connect to a Sybase server. OleDbConnection Conn= new OleDbConnection(); string connstr = "Provider=Sybase ASE OLE DB Provider;Data Source=SERVER;User...
8
by: fniles | last post by:
Can I change the connection time out in VB.Net 2003 and MS Access (using OLEDbConnection) ? When I use Connect Timeout = 60 in the connectionstring, I get an error "Multiple-step OLE DB operation...
1
by: Mel | last post by:
I am performing the same recordset multiple times, just passing different parameters each time. Is there a way to do this more efficiently without having to close and re-open the connection and...
16
by: SyGC | last post by:
Hello, Im trying to connect to a MySQL DB on my home network (testing purposes) using the following VB.NET code; Imports System.Data.OleDb Private Sub Button3_Click(ByVal sender As...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.