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 1310
Hi Perin,
In web.config file, add the section below.
<configuratio n>
<appSettings>
<add key="Connection String"
value="server=l ocalhost;databa se=testdb;uid=s a;password=secr et;" />
</appSettings>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
In your code, access like this..
strConnection = ConfigurationSe ttings.AppSetti ngs("Connection String")
sqlConn = New SqlConnection(s trConnection)
sqlCmd = New SqlCommand("SEL ECT * 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
ConfigurationSe ttings.AppSetti ngs("Connection String")
Imports System.Configur ation.Configura tionSettings
"John Paul. A" <Jo*******@disc ussions.microso ft.com> wrote in message
news:13******** *************** ***********@mic rosoft.com... Hi Perin, In web.config file, add the section below.
<configuratio n> <appSettings> <add key="Connection String" value="server=l ocalhost;databa se=testdb;uid=s a;password=secr et;" /> </appSettings> <system.web> <customErrors mode="Off"/> </system.web> </configuration>
In your code, access like this..
strConnection = ConfigurationSe ttings.AppSetti ngs("Connection String") sqlConn = New SqlConnection(s trConnection) sqlCmd = New SqlCommand("SEL ECT * 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.SQLConnectio n1.ConnectionSt ring =
System.Configur ation.Configura tionSettings.Ap pSettings("CS")
HTH.
Regards
Jignesh.
"Perin" <ja************ ****@hotmail.co m> wrote in message
news:9A******** *************** ***********@mic rosoft.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 ConfigurationSe ttings, so that
you arent relying on magic constants...
class MyConfiguration
{
public static string ConnectionStrin g { get { return ConfigurationSe ttings.AppSetti ngs["ConnectionStri ng"];
} }
}
then: SqlConnection conn = new SqlConnection(M yConfiguration. ConnectionStrin g);
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. <configuratio n> <appSettings> <add key="Connection String" value="server=l ocalhost;databa se=testdb;uid=s a;password=secr et;" /> </appSettings> <system.web> <customErrors mode="Off"/> </system.web> </configuration> In your code, access like this..
strConnection = ConfigurationSe ttings.AppSetti ngs("Connection String") sqlConn = New SqlConnection(s trConnection) sqlCmd = New SqlCommand("SEL ECT * 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 ConfigurationSe ttings, so that you arent relying on magic constants...
class MyConfiguration { public static string ConnectionStrin g { get { return ConfigurationSe ttings.AppSetti ngs["ConnectionStri ng"]; } } }
then: SqlConnection conn = new SqlConnection(M yConfiguration. ConnectionStrin g);
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. <configuratio n> <appSettings> <add key="Connection String" value="server=l ocalhost;databa se=testdb;uid=s a;password=secr et;" /> </appSettings> <system.web> <customErrors mode="Off"/> </system.web> </configuration> In your code, access like this..
strConnection = ConfigurationSe ttings.AppSetti ngs("Connection String") sqlConn = New SqlConnection(s trConnection) sqlCmd = New SqlCommand("SEL ECT * 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 one column per element, each column is VARCHAR
Does MySQL has anything special for XML data?
Is there any software which helps to store XML data...
|
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 fine, and I can read the connection
string in and connect. But at the moment everytime a connection is made to
the database to get records, update...
|
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 the place I should store the
connection string?
If I call System.Configuration.ConfigurationSettings.AppConfig from the
data class library, will...
|
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 problem?
Actually, my first question is, why is it a security risk? As I understand
it, it is impossible to download the web.config file. Is this not the...
| |
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
on my development and production server. If I use the global.asax file, then
it is in the code behing, compiled part. Thus I can't change the setting...
|
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 password would be different
than the one the user enters for ASP.NET forms authentication. The
ID/password in question is used by the application,...
|
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 database name. I need to provide
the client application with this info for connecting to both a test SQL
Server and a production server.
I would prefer...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |