Solved

Best place to store connection string/class

Posted on 2004-10-11
4
326 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

861 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

23 Experts available now in Live!

Get 1:1 Help Now