Changing connection string at runtime from login form

T

Tim Nelson

I am building a data bound application for SQL server which all the
forms I use sqlconnections generated by VS. I want to have a login form
that changes the connection depending upon login parameters. The only
way I can think to do this is to:

1. Connect in the login form.
2. Get the connection string.
3. Close the connection.
4. Pass the connection string in the new forms constructor and assign
the connection string after the component is initialized.

Is there a cleaner way to just pass the sqlconnection or something?
Thanks.
 
D

DotNet Coder

Hi Tim,

Yes, you can pass around a SqlConnection object as needed. But, a
cleaner way might be to have a static SqlConnection that all your forms
would have access to and then just dynamically change the
ConnectionString porperty. I don't know how this would affect
performance (connectiion pooling and all that) without doing some
testing, but it seems that it would be a cleaner implementation.

Another way to do it would be to create a data layer library (or class,
your choice; I always prefer to keep my data layer away from my gui and
BLL). In this data layer library, you would define methods to
dynamically alter a SqlConnection's ConnectionString property and then
return the SqlConnection or SqlCommand or whatever.

HTH,
~d
 

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