Hi,
I am using SQL Server as a Database in my ASP.NET application. Can anyone
tell me, how to store my connection string in web.config file and access it
from my application.
It is very urgent please..
--
Perin 6 1299
Hi Perin,
In web.config file, add the section below.
<configuration>
<appSettings>
<add key="ConnectionString"
value="server=localhost;database=testdb;uid=sa;pas sword=secret;" />
</appSettings>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
In your code, access like this..
strConnection = ConfigurationSettings.AppSettings("ConnectionStrin g")
sqlConn = New SqlConnection(strConnection)
sqlCmd = New SqlCommand("SELECT * FROM Customers", sqlConn)
sqlConn.Open()
Very simple..
Rgds,
John Paul. A
"Perin" wrote: Hi, I am using SQL Server as a Database in my ASP.NET application. Can anyone tell me, how to store my connection string in web.config file and access it from my application. It is very urgent please..
-- Perin
Just remember to add the following import statement at the top of any
module/Codebehind/class that will be using
ConfigurationSettings.AppSettings("ConnectionStrin g")
Imports System.Configuration.ConfigurationSettings
"John Paul. A" <Jo*******@discussions.microsoft.com> wrote in message
news:13**********************************@microsof t.com... Hi Perin, In web.config file, add the section below.
<configuration> <appSettings> <add key="ConnectionString" value="server=localhost;database=testdb;uid=sa;pas sword=secret;" /> </appSettings> <system.web> <customErrors mode="Off"/> </system.web> </configuration>
In your code, access like this..
strConnection = ConfigurationSettings.AppSettings("ConnectionStrin g") sqlConn = New SqlConnection(strConnection) sqlCmd = New SqlCommand("SELECT * FROM Customers", sqlConn) sqlConn.Open()
Very simple..
Rgds, John Paul. A
"Perin" wrote:
Hi, I am using SQL Server as a Database in my ASP.NET application. Can anyone tell me, how to store my connection string in web.config file and access it from my application. It is very urgent please..
-- Perin
In web.Config you have an <appSettings> section.
Insert following lines
<add key="CS"
value=" Write connection string here." />
From codebehind pages access CS by
Me.SQLConnection1.ConnectionString =
System.Configuration.ConfigurationSettings.AppSett ings("CS")
HTH.
Regards
Jignesh.
"Perin" <ja****************@hotmail.com> wrote in message
news:9A**********************************@microsof t.com... Hi, I am using SQL Server as a Database in my ASP.NET application. Can anyone tell me, how to store my connection string in web.config file and access
it from my application. It is very urgent please..
-- Perin
Hello John,
Even better would be a class that wraps the ConfigurationSettings, so that
you arent relying on magic constants...
class MyConfiguration
{
public static string ConnectionString { get { return ConfigurationSettings.AppSettings["ConnectionString"];
} }
}
then: SqlConnection conn = new SqlConnection(MyConfiguration.ConnectionString);
This way, errors are caught at compile time, rather than runtime. Also, if
you happen to change the name of the setting in the app.config, you can change
it in one spot, rather than having to do a global search/replace.
--
Matt Berther http://www.mattberther.com Hi Perin, In web.config file, add the section below. <configuration> <appSettings> <add key="ConnectionString" value="server=localhost;database=testdb;uid=sa;pas sword=secret;" /> </appSettings> <system.web> <customErrors mode="Off"/> </system.web> </configuration> In your code, access like this..
strConnection = ConfigurationSettings.AppSettings("ConnectionStrin g") sqlConn = New SqlConnection(strConnection) sqlCmd = New SqlCommand("SELECT * FROM Customers", sqlConn) sqlConn.Open() Very simple..
Rgds, John Paul. A "Perin" wrote:
Hi, I am using SQL Server as a Database in my ASP.NET application. Can anyone tell me, how to store my connection string in web.config file and access it from my application. It is very urgent please.. -- Perin
Dear MAtt Berther,
What you are saying is right.
Thanks for your guidance.
Rgds,
John Paul. A
"Matt Berther" wrote: Hello John,
Even better would be a class that wraps the ConfigurationSettings, so that you arent relying on magic constants...
class MyConfiguration { public static string ConnectionString { get { return ConfigurationSettings.AppSettings["ConnectionString"]; } } }
then: SqlConnection conn = new SqlConnection(MyConfiguration.ConnectionString);
This way, errors are caught at compile time, rather than runtime. Also, if you happen to change the name of the setting in the app.config, you can change it in one spot, rather than having to do a global search/replace.
-- Matt Berther http://www.mattberther.com
Hi Perin, In web.config file, add the section below. <configuration> <appSettings> <add key="ConnectionString" value="server=localhost;database=testdb;uid=sa;pas sword=secret;" /> </appSettings> <system.web> <customErrors mode="Off"/> </system.web> </configuration> In your code, access like this..
strConnection = ConfigurationSettings.AppSettings("ConnectionStrin g") sqlConn = New SqlConnection(strConnection) sqlCmd = New SqlCommand("SELECT * FROM Customers", sqlConn) sqlConn.Open() Very simple..
Rgds, John Paul. A "Perin" wrote:
Hi, I am using SQL Server as a Database in my ASP.NET application. Can anyone tell me, how to store my connection string in web.config file and access it from my application. It is very urgent please.. -- Perin This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: jacob nikom |
last post by:
Hi,
I would like to store XML files in MySQL. What is the best solution:
1. Convert it to string and store it as CLOB/text
2. Serialize it and store as byte array
3. Flatten it out and create...
|
by: Steve |
last post by:
C#
I am trying to store my connection settings in a config file, mainly so I
can easily change the db that the app connects to without doing a release of
code. I have the config file sorted...
|
by: Alberto |
last post by:
I have to store a connection string to a data base but I don't know where.
Where do you prefer store it, in a text file or in a xml file?
Thank you.
|
by: Chris Dunaway |
last post by:
I have a web service that references a data class library which performs
SQL Server access. Since the web service is also a class library, there is
no App.Config, only Web.config. Is Web.Config...
|
by: Simon Harvey |
last post by:
Hi everyone,
As I understand it, storing an applications SQL Server connection string in
the web.config file is a security risk. I'm wondering then, what the
simplest solution is to this...
| |
by: Leo Muller |
last post by:
I am about to deploy my first ASP.NET project.
But, I was used to store my variables, such as connection strings, in the
global.asa file, in an application. However, these variables are different...
|
by: Guadala Harry |
last post by:
What are my options for *securely* storing/retrieving the ID and password
used by an ASP.NET application for accessing a SQL Server (using SQL Server
authentication)? Please note that this ID and...
|
by: Merk |
last post by:
I'm looking for a safe and maintainable way to store connection string info
(connecting to SQL Server 2005 from .NET 2.0 Windows Forms client app);
things like server name or IP address and...
|
by: Man T |
last post by:
I just wonder what is/are your practices to build the SQL Server connection
string?
Use object to build the connection string from config file or somewhere?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |