Framework 1.0 -> 1.1: Data Adapter loses connection string (using CommandBuilder)

I

Ian Varley

Hi all,

Just discovered a breaking change from framework version 1.0 to
version 1.1. What I am doing is filling a DataSet from a connected
DataAdapter (using a CommandBuilder object), closing the connection,
and then later using that same DataAdapter and DataSet to send an
update to the database. Works fine under 1.0, but as soon as I
upgraded to 1.1 I got the message: "The Connection string has not been
initialized." Here's the code:

First block:

SqlConnection cn = new SqlConnection(CONNECTION_STRING);
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM MyTable", cn);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
cn.Open();
da.Fill(this.d,"MyTable");
DataRow r = d.Tables("MyTable").Rows.Find(ID); // find given ID
cn.Close();

Second block (called later

r("Property1") = "BlahBlahBlah"
r("Last_Updated") = DateTime.Now;
// ... etc. - update many fields in this row
da.Update(d,"MyTable");

Any idea what I need to change for this to work correctly under 1.1?
The specific difference seems to be that the property
"DataAdapter.SelectCommand._activeConnection._connectionString" keeps
its value under 1.0 but does not keep it under 1.1. I'm sure that's by
design (?) but I need to know how to either get it to keep the
connection string, or figure out how to supply the connection string
again when it's time to run the update.

(Thankfully, .NET lets you choose which installed framework version to
use, so this isn't an emergency, but I'd like to figure it out so I
can move forward.)

Thanks!
Ian
(e-mail address removed)
 
I

Ian Varley

Hi all,

Anyone have experience with (or solutions for) the issue below?

Thanks,
Ian Varley
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top