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

D

Darrel

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
 
D

Darrel

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.ToString())
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;
 
J

Juan T. Llibre

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;database=pubs"/>
</appSettings>

You can retrieve it with :

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

and insert MyKey.Text anywhere you wantto.
 
D

Darrel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top