Solved

Best place to store connection string/class

Posted on 2004-10-11
4
324 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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now