Common Connection

  • Thread starter Thread starter Lora Connors
  • Start date Start date
L

Lora Connors

I'm working on an ADO.NET project. I'd like to declare a
Common Variable that can store the Connection String
values for a Database. I need this variable to be able to
initialise the database connection for all
OledbDataAdapters across all Form modules. Thanks!
 
Hi Lora,

You might put your connection string inside app.config file, example:
<configuration>
<appSettings>
<add key="connectionString" value="data source=myserver;initial
catalog=Apps;Integrated Security=SSPI;packet size=4096" />
</appSettings>
</configuration>

either bind it at design time (DynamicProperties) or access it using

string conn =
System.Configuration.ConfigurationSettings.AppSettings["YourConnection"];
 
It depends where you use it.
In Window form:
Place this variable or constant in a VB module.
Const ConnectString = "Data Source=..."
In Web form:
using Application("ConnectString") = "Data Source=..."
or put it in Web.config

Bin Song, MCP
 
Back
Top