Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Public Connection

Status
Not open for further replies.

abdullauthan

Programmer
Apr 20, 2000
64
SA
I declared a connection as Public in a module and it always gives me an error when I pass the connectstring from the login page.

When I declare the connection with Dim within the button_click event, it works fine.

I'm new to ASP.Net and I'm declaring the connection Public because I hope I can use the connection from other pages to open tables.

If there is any other way around, please let me know.
 
abdull: Do a search here at Tek-Tips - there are several threads on this -- a couple very good (regarding the best place to "store" a connection string, etc). See what you can find - don't have the thread references available to me at the moment -- but I would spend some time looking for them -- as they are very good and cover your question completely.
 
Hi gurus! - my 2 cents worth...
As far as I know in ASP one stored Global Variables in the Global.asa and now in ASP.Net in the Global.asax file. We used to always Create a ConnectString here and it is visible anywhere.

Application("sSQLConn") = "Initial Catalog=SomeDB;Data Source=SomeServer;Integrated Security=SSPI;"

Then you can retrieve this from anywhere...

CNN.ConnectionString = Application("sSQLConn")

Rgds
Len


 
Another way would be storing the connection string in Web.config file:
Code:
<configuration>
 <appSettings>
   <add key=&quot;ConnectionString&quot; value=&quot;server=localhost;uid=sa;password=;database=MyDB&quot; />
 </appSettings>
</configuration>
You can get a reference on it from your code behind:
Code:
string conn = System.Configuration.ConfigurationSettings.AppSettings[&quot;ConnectionString&quot;];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top