473,320 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Where is best place to put DB connection string?

Hi:

My ASP.NET app opens and closes database connection in several pages.
Rather than hard coding string into every page, is there a place I can put
it where all pages will be able to access it. In days of fat client
programming, I put in INI file. Looking for similar solution.

Thanks,
Charlie
Nov 18 '05 #1
8 1525
Make use of web.config

"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:ep*************@TK2MSFTNGP11.phx.gbl...
Hi:

My ASP.NET app opens and closes database connection in several pages.
Rather than hard coding string into every page, is there a place I can put
it where all pages will be able to access it. In days of fat client
programming, I put in INI file. Looking for similar solution.

Thanks,
Charlie

Nov 18 '05 #2
Hi, Charlie,

Here is a sample:

http://samples.gotdotnet.com/quickst...%2fconfig1.src

Greetings
Martin
"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:ep*************@TK2MSFTNGP11.phx.gbl...
Hi:

My ASP.NET app opens and closes database connection in several pages.
Rather than hard coding string into every page, is there a place I can put
it where all pages will be able to access it. In days of fat client
programming, I put in INI file. Looking for similar solution.

Thanks,
Charlie

Nov 18 '05 #3
Most people aim for web.config, but I would at least encrypt the string if
you do that. There are free books on ASP.NET security at
http://msdn.microsoft.com/architecture. Look at the "Patterns and Practices"
section.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:ep*************@TK2MSFTNGP11.phx.gbl...
Hi:

My ASP.NET app opens and closes database connection in several pages.
Rather than hard coding string into every page, is there a place I can put
it where all pages will be able to access it. In days of fat client
programming, I put in INI file. Looking for similar solution.

Thanks,
Charlie

Nov 18 '05 #4
Max
Most people use the web.config, but it certain cases I've found it more
secure to just store it as a global variable within your app where it is
compiled.

-Max

"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:ep*************@TK2MSFTNGP11.phx.gbl...
Hi:

My ASP.NET app opens and closes database connection in several pages.
Rather than hard coding string into every page, is there a place I can put
it where all pages will be able to access it. In days of fat client
programming, I put in INI file. Looking for similar solution.

Thanks,
Charlie

Nov 18 '05 #5
If you "store it as a global variable" it must be defined (read
"hard-coded") somewhere. I believe "where" was the question.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Max" <ma*****@portvista.com> wrote in message
news:lh**********************@twister.tampabay.rr. com...
Most people use the web.config, but it certain cases I've found it more
secure to just store it as a global variable within your app where it is
compiled.

-Max

"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:ep*************@TK2MSFTNGP11.phx.gbl...
Hi:

My ASP.NET app opens and closes database connection in several pages.
Rather than hard coding string into every page, is there a place I can put it where all pages will be able to access it. In days of fat client
programming, I put in INI file. Looking for similar solution.

Thanks,
Charlie


Nov 18 '05 #6
Max
public class myvars
public shared strConnection = "blah blah blah happy now?"
end class

imports YourAppName.myvars

strConnection is now a variable you can use anywhere

Be careful what changes this variable as it is shared, and turn off page
errors so it doesn't bomb out and show your connection string to everyone.

-Max
"Kevin Spencer" <ke***@takempis.com> wrote in message
news:OP*************@tk2msftngp13.phx.gbl...
If you "store it as a global variable" it must be defined (read
"hard-coded") somewhere. I believe "where" was the question.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Max" <ma*****@portvista.com> wrote in message
news:lh**********************@twister.tampabay.rr. com...
Most people use the web.config, but it certain cases I've found it more
secure to just store it as a global variable within your app where it is
compiled.

-Max

"Charlie@CBFC" <ch*****@comcast.net> wrote in message
news:ep*************@TK2MSFTNGP11.phx.gbl...
Hi:

My ASP.NET app opens and closes database connection in several pages.
Rather than hard coding string into every page, is there a place I can put it where all pages will be able to access it. In days of fat client
programming, I put in INI file. Looking for similar solution.

Thanks,
Charlie



Nov 18 '05 #7
Max
public shared strConnection as string = "your conn"

you get the idea

"Max" <ma*****@portvista.com> wrote in message
news:%D**********************@twister.tampabay.rr. com...
public class myvars
public shared strConnection = "blah blah blah happy now?"
end class

Nov 18 '05 #8
Hi, Max,

As Kevin stated, with this technique the string is hard-coded, which in
other words means it is *not* configurable.

Greetings
Martin
"Max" <ma*****@portvista.com> wrote in message
news:%E**********************@twister.tampabay.rr. com...
public shared strConnection as string = "your conn"

you get the idea

"Max" <ma*****@portvista.com> wrote in message
news:%D**********************@twister.tampabay.rr. com...
public class myvars
public shared strConnection = "blah blah blah happy now?"
end class


Nov 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mike.miller | last post by:
You could create a static class for the connection with static properties for the connection object itself and all of the associated properties. Just be aware that only one object can use a...
4
by: Ed_P. | last post by:
Hello, I have the following scenario: I have a solution with 4 projects Project1 = MainWindow (Windows EXE) Project2 = PresentationLayer (DLL) Project3 = BusinessLayer (DLL) Project4 =...
2
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...
5
by: Saulot | last post by:
Hi, Facing a big problem. In my Default.aspx page, I open a connection with ma Sql Server DataBase through my objects framework (A "SetDefaultConnectionString" property which open my...
5
by: Fernando Lopes | last post by:
Hi there. In your opinion, where is the best place to put the connection string of a web application? Web.config, a constant into the code? I'm not using a component server, so it's not an...
6
by: ad | last post by:
We usually store the connection string of Web Applicaiton in Web.Config. Now I want to develop WinForm Application. Where is the better place to store the conneciton string?
4
by: Andrew | last post by:
Hello, friends, I have two questions: (1) In asp.net, where is the best place to store DB connection string? (We have .dll to handle all DB queries.) (2) Any sample source code for client...
5
by: csgraham74 | last post by:
Hi guys, Basically i have been developing in dotnet for a couple of years but ive had a few issues in regards to error handling. For example - I have a class that i call passing in a stored...
3
by: Nemisis | last post by:
Guys, I would like to write a error handler, or something, that will allow me to write to a database when an error occurs on my site. I am trying to implement this in the global.asax file a the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.