PC Review


Reply
Thread Tools Rate Thread

DataAdapter is not using correct connection string

 
 
Andi
Guest
Posts: n/a
 
      5th May 2005
Hello,

I'm hoping that someone out there can help me out of this.
I'm having several DataAdapters which are referencing all to the same
OleDbConnection object. At construction time of my DAL component, the
connection is instantiated (but not opened yet) and given a connection
string.
Once I want to access the database, I construct an instance of the
according DataAdapter, assign the OleDbConnection to its SELECT,
INSERT, UPDATE and DELETE commands and finally open the connection.
When I want to execute the query, e.g. when I call the Fill() method of
the adapter, I get an exception telling me that the database could not
be found.
The weird thing about this is the fact, that the database path returned
by the exception is _not_ the one I specified in my connection string
in the first place.
In fact, the path stated by the exception points to an old location I
used several days ago.
So I debugged my application and stopped at the line containing the
Fill() command:

try
{
...
-> myAdapter.Fill( dataset, tablename);
}
catch(Exception ex)
{
...
}

When examining the connections assigned to the SELECT, INSERT, UPDATE
and DELETE commands of 'myAdapter', all of them pointed to the correct
database.
I really don't know where the Fill() command gets the old path from. Am
I overlooking something?

Andi

 
Reply With Quote
 
 
 
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      5th May 2005
Hi,

DataAdapter.Fill uses DataAdapter.SelectCommand.Connection instance.
Make sure it is the one you want (are you sure that the connection string is
ok?).

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

"Andi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I'm hoping that someone out there can help me out of this.
> I'm having several DataAdapters which are referencing all to the same
> OleDbConnection object. At construction time of my DAL component, the
> connection is instantiated (but not opened yet) and given a connection
> string.
> Once I want to access the database, I construct an instance of the
> according DataAdapter, assign the OleDbConnection to its SELECT,
> INSERT, UPDATE and DELETE commands and finally open the connection.
> When I want to execute the query, e.g. when I call the Fill() method of
> the adapter, I get an exception telling me that the database could not
> be found.
> The weird thing about this is the fact, that the database path returned
> by the exception is _not_ the one I specified in my connection string
> in the first place.
> In fact, the path stated by the exception points to an old location I
> used several days ago.
> So I debugged my application and stopped at the line containing the
> Fill() command:
>
> try
> {
> ...
> -> myAdapter.Fill( dataset, tablename);
> }
> catch(Exception ex)
> {
> ...
> }
>
> When examining the connections assigned to the SELECT, INSERT, UPDATE
> and DELETE commands of 'myAdapter', all of them pointed to the correct
> database.
> I really don't know where the Fill() command gets the old path from. Am
> I overlooking something?
>
> Andi
>



 
Reply With Quote
 
Andi
Guest
Posts: n/a
 
      5th May 2005
Hi Miha,

thank you for your quick reply.
What you mentioned is exactly the point. When I'm in my debug session
I'm looking at this very property of my DataAdapter. The
ConnectionString property inside the
DataAdapter.SelectCommand.Connection contains the correct path and
should be ok, as it is constructed via template where only the path to
the database is inserted (and it worked with the old location of the
database).
The DataSource property of DataAdapter.SelectCommand.Connection also
points to the correct database so I'm quite at a loss

Andi

Miha Markic [MVP C#] schrieb:
> Hi,
>
> DataAdapter.Fill uses DataAdapter.SelectCommand.Connection instance.
> Make sure it is the one you want (are you sure that the connection

string is
> ok?).
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> www.rthand.com
> SLODUG - Slovene Developer Users Group www.codezone-si.info
>
> "Andi" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hello,
> >
> > I'm hoping that someone out there can help me out of this.
> > I'm having several DataAdapters which are referencing all to the

same
> > OleDbConnection object. At construction time of my DAL component,

the
> > connection is instantiated (but not opened yet) and given a

connection
> > string.
> > Once I want to access the database, I construct an instance of the
> > according DataAdapter, assign the OleDbConnection to its SELECT,
> > INSERT, UPDATE and DELETE commands and finally open the connection.
> > When I want to execute the query, e.g. when I call the Fill()

method of
> > the adapter, I get an exception telling me that the database could

not
> > be found.
> > The weird thing about this is the fact, that the database path

returned
> > by the exception is _not_ the one I specified in my connection

string
> > in the first place.
> > In fact, the path stated by the exception points to an old location

I
> > used several days ago.
> > So I debugged my application and stopped at the line containing the
> > Fill() command:
> >
> > try
> > {
> > ...
> > -> myAdapter.Fill( dataset, tablename);
> > }
> > catch(Exception ex)
> > {
> > ...
> > }
> >
> > When examining the connections assigned to the SELECT, INSERT,

UPDATE
> > and DELETE commands of 'myAdapter', all of them pointed to the

correct
> > database.
> > I really don't know where the Fill() command gets the old path

from. Am
> > I overlooking something?
> >
> > Andi
> >


 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      5th May 2005
Hi Andi,

Try the same select statement with OleDbCommand.ExecuteQuery.
Just to check if the connection string and things are ok.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group www.codezone-si.info

"Andi" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Miha,
>
> thank you for your quick reply.
> What you mentioned is exactly the point. When I'm in my debug session
> I'm looking at this very property of my DataAdapter. The
> ConnectionString property inside the
> DataAdapter.SelectCommand.Connection contains the correct path and
> should be ok, as it is constructed via template where only the path to
> the database is inserted (and it worked with the old location of the
> database).
> The DataSource property of DataAdapter.SelectCommand.Connection also
> points to the correct database so I'm quite at a loss



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataAdapter SQL string at runtime John Microsoft VB .NET 4 6th Jan 2009 04:37 PM
DataAdapter and passing query string question stephen Microsoft ASP .NET 0 5th Jun 2008 09:24 PM
dataadapter wizard connection string =?Utf-8?B?am9obiBzbWl0aGVycw==?= Microsoft ASP .NET 5 6th Sep 2004 03:08 PM
Re: Connection string setting for DataAdapter Carl Prothman [MVP] Microsoft ADO .NET 0 23rd May 2004 06:19 AM
Re: Connection string setting for DataAdapter Pete Wright Microsoft ADO .NET 0 22nd May 2004 08:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:29 AM.