sqlConnection question

M

Mike D

I hate to be a newbie but I am trying to write an C# web application with
multiple Web Forms. Once a user selects a row from a datagrid, the primary
key is passed to the next window and so on. The sqlConnections on all the
windows point to a SQL 2000 Test database.

How do I go about creating a global or session connection that all the
sqlDataAdapters can use while I'm creating my web forms? I don't want to go
back through all the forms and change the connection.

Thanks
Mike
 
N

Nicholas Paldino [.NET/C# MVP]

Mike,

What I would do is have a static property which will return the
connection, configured. In the static property, it will create the new
connection, and then set the connection string, and any other properties
that need to be set. Whatever you do, you do not want to use the same
instance of a connection everywhere, but rather, get a connection instance,
open it, perform your operation, and then close it.

Then, when you want to change the connection string, you can change it
in one place, or even have the app read it from the web.config file.

Hope this helps.
 

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