473,386 Members | 1,630 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,386 software developers and data experts.

asp.net 2...where do you put your DB connection strings?

I've been taught that, at least in 1.1, you put your DB connection strings
in the WebConfig file and access them from there as needed.

In 2.0, it looks like I can do the same, but it's been suggested that I use
the Web Site Admin Tool Wizard to store them. So, I have a few questions:

Should I? The wizard itself says: "Do not store sensitive information, such
as user names, passwords, or database connection strings in application
settings." Is that the wrong place? If so, where should I put it?

If not, it looks like it just sticks the app setting back in the web config
file like I used to do manually. As such, is there any value in using the
Wizard to just add a line of text to my config file?

-Darrel
Apr 13 '06 #1
5 1371
You could put them in web.config...and encrypt them.

http://weblogs.asp.net/owscott/archi...29/421063.aspx

http://www.ondotnet.com/pub/a/dotnet...onnstring.html

http://davidhayden.com/blog/dave/arc...1/17/2572.aspx

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Darrel" <no*****@nospam.com> wrote in message news:OZ**************@TK2MSFTNGP02.phx.gbl...
I've been taught that, at least in 1.1, you put your DB connection strings in the WebConfig file
and access them from there as needed.

In 2.0, it looks like I can do the same, but it's been suggested that I use the Web Site Admin
Tool Wizard to store them. So, I have a few questions:

Should I? The wizard itself says: "Do not store sensitive information, such as user names,
passwords, or database connection strings in application settings." Is that the wrong place? If
so, where should I put it?

If not, it looks like it just sticks the app setting back in the web config file like I used to do
manually. As such, is there any value in using the Wizard to just add a line of text to my config
file?

-Darrel

Apr 13 '06 #2
I doubt you'll be able to tackle encryption right now. You have to first
figure out how to make a connection.
Have you submitted a web search using the terms: test connection string
vb.net

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/

"Juan T. Llibre" <no***********@nowhere.com> wrote in message
news:ei*************@TK2MSFTNGP02.phx.gbl...
You could put them in web.config...and encrypt them.

http://weblogs.asp.net/owscott/archi...29/421063.aspx

http://www.ondotnet.com/pub/a/dotnet...onnstring.html

http://davidhayden.com/blog/dave/arc...1/17/2572.aspx

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Darrel" <no*****@nospam.com> wrote in message
news:OZ**************@TK2MSFTNGP02.phx.gbl...
I've been taught that, at least in 1.1, you put your DB connection
strings in the WebConfig file and access them from there as needed.

In 2.0, it looks like I can do the same, but it's been suggested that I
use the Web Site Admin Tool Wizard to store them. So, I have a few
questions:

Should I? The wizard itself says: "Do not store sensitive information,
such as user names, passwords, or database connection strings in
application settings." Is that the wrong place? If so, where should I put
it?

If not, it looks like it just sticks the app setting back in the web
config file like I used to do manually. As such, is there any value in
using the Wizard to just add a line of text to my config file?

-Darrel


Apr 13 '06 #3
I doubt you'll be able to tackle encryption right now. You have to first
figure out how to make a connection.
Have you submitted a web search using the terms: test connection string
vb.net


I can't even get my DB query function to accept the connection string as a
string in 2.0 ;o)

Maybe the issue is my 'antiquated 1.1' DB functions. This is what I have:

======================================

Dim strConnect As ConnectionStringSettings
strConnect = ConfigurationManager.ConnectionStrings("DBConn")
'the above is not working, obviously

Dim strChk As String
Dim objConnect As New
System.Data.OleDb.OleDbConnection(strConnect.ToStr ing())
objConnect.Open()

strChk = "SELECT name, pwd FROM pf_users WHERE name = ? AND pwd = ? AND
admin = 1"

Dim objCommand As New System.Data.OleDb.OleDbCommand(strChk, objConnect)
Dim objOleDbAdapter As New System.Data.OleDb.OleDbDataAdapter
objCommand.Parameters.Add("@name",
System.Data.OleDb.OleDbType.VarChar).Value = strUser
objCommand.Parameters.Add("@pwd", System.Data.OleDb.OleDbType.VarChar).Value
= strPwd
objOleDbAdapter.SelectCommand = objCommand
objOleDbAdapter.Fill(DS, "users")

======================================

-Darre;
Apr 13 '06 #4
If you want to use 2.0 syntax, try this :

In web.config :

<connectionStrings>
<add name="selectDocs"
connectionString="your_connection_string"
providerName="System.Data.SqlClient" />
</connectionStrings>

To display it in an aspx page :

<%@ Page Language="vb" %>
<HTML>
<HEAD>
<title>Retrieving a Connection String with ASP.NET 2.0</title>
</HEAD>
<body>
<form id="Form1" runat="server">
<asp:label id="key1" runat="server" /><br/>
<asp:Literal runat="server" Text="<%$ ConnectionStrings:selectDocs%>" />
</form>
</body>
</HTML>

You can use : <%$ ConnectionStrings:selectDocs%>
to insert the text of your connection string anywhere you want to.

You can also use AppSettings.

If you have this AppSettings key in web.config :

<appSettings>
<add key="SQLConnection" value="server=localhost;trusted_connection=true;da tabase=pubs"/>
</appSettings>

You can retrieve it with :

Dim MyKey As String = ConfigurationSettings.AppSettings("SQLConnection")

and insert MyKey.Text anywhere you wantto.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Darrel" <no*****@nospam.com> wrote in message news:OT**************@TK2MSFTNGP02.phx.gbl...
I doubt you'll be able to tackle encryption right now. You have to first
figure out how to make a connection.
Have you submitted a web search using the terms: test connection string vb.net


I can't even get my DB query function to accept the connection string as a string in 2.0 ;o)

Maybe the issue is my 'antiquated 1.1' DB functions. This is what I have:

======================================

Dim strConnect As ConnectionStringSettings
strConnect = ConfigurationManager.ConnectionStrings("DBConn")
'the above is not working, obviously

Dim strChk As String
Dim objConnect As New System.Data.OleDb.OleDbConnection(strConnect.ToStr ing())
objConnect.Open()

strChk = "SELECT name, pwd FROM pf_users WHERE name = ? AND pwd = ? AND admin = 1"

Dim objCommand As New System.Data.OleDb.OleDbCommand(strChk, objConnect)
Dim objOleDbAdapter As New System.Data.OleDb.OleDbDataAdapter
objCommand.Parameters.Add("@name", System.Data.OleDb.OleDbType.VarChar).Value = strUser
objCommand.Parameters.Add("@pwd", System.Data.OleDb.OleDbType.VarChar).Value = strPwd
objOleDbAdapter.SelectCommand = objCommand
objOleDbAdapter.Fill(DS, "users")

======================================

-Darre;

Apr 13 '06 #5
> Dim MyKey As String = ConfigurationSettings.AppSettings("SQLConnection")

That's the problem.VS.net tells me the above syntax is deprecated.

So I use ConfigurationManager.ConnectionStrings("DBConn"), but that isn't a
string, and my OleDbCommmand doesn't accept that as a value.

-Darrel

Apr 13 '06 #6

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

Similar topics

4
by: Matthew Wells | last post by:
FIRST OF ALL, I APPRECIATE PEOPLE SENDIUNG ME LINKS TO WEB SITES FOR CONNECTION STRINGS BUT AS I'VE SAID BEFORE THAT IS NOT WHAT I NEED. I CAN EASILY OPEN AN ADO CONNECTION OBJECT TO AS400. I...
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 =...
5
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...
5
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...
4
by: Matt Colegrove | last post by:
I'm working on a web app that is published to a hosting service. I'm developing it on my local PC with VS 2005 and SQL Express. The hosting service DB is SQL Server 2000. I have two...
2
by: A. User | last post by:
Hello, Where does the ODBC Data Source Admin tool store the connection information for User, System or File DSNs? A coworker created/used several ODBC connections on his machine, we backed up...
37
by: sam44 | last post by:
Hi, At startup the user log on and chooses the name of a client from a dropdownlist, which then changes dynamically the connection string (the name of the client indicates which database to use)....
3
by: Harry Strybos | last post by:
Hi All I have a really strange problem occurring in my application. When I read in the application settings for connection strings the following happens: Here are my connection string settings...
9
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a question about storing the connection strings to the database in a config file or database. My manager wants me to store all the connection strings in a database, but I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...

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.