Solved

Best place to store connection string/class

Posted on 2004-10-11
4
329 Views
Last Modified: 2008-02-01
I'm building an asp.net website.  
For the asp.net web pages that need a connection string, I can put the connection string in the web.config file and use it/change it as needed.  I was planning on creating a few separate projects for the reusable parts, so was going to create a few stand alone components.  However, the vb.net project does not have a web.config file, so where is the best place to store the connection string?

Also saw a friend put classes within a folder in his asp.net web project.  He was able to use web.config to store his connection string.  Is that a good idea?

Thanks for any help.
0
Comment
Question by:davexxxx
4 Comments
 
LVL 4

Accepted Solution

by:
eozz_2000 earned 50 total points
ID: 12281834
I store the connectionString of my connections in a file stored in a folder that is not visible to the users that acces my application.
0
 
LVL 16

Assisted Solution

by:MikeMCSD
MikeMCSD earned 50 total points
ID: 12427818
Web.config is the best place:

<configuration>
<appSettings>

<add key="ConnectionString"
        value="server=localhost;Trusted_Connection=true;database=DCP"/>

</appSettings>
.......

then put this in your code:

Private Shared ReadOnly Property connectionString() As String
        Get
            Return ConfigurationSettings.AppSettings("ConnectionString")
        End Get
    End Property

and to use it, just add the variable:

Dim connection As New SqlConnection(connectionString)
..
..

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question