not 'getting' asp.net 2.0's web configuration tool

D

Darrel

I haven't made it very far into my first 2.0 project.

In the past, to connect to a DB, I'd store the connection string in
web.config and just grab it from my codebehind page:

connectionString = ConfigurationSettings.AppSettings("dbConnection")

Well, 2.0 is telling me that is deprecated. And via some googling, it seems
like I'm not even supposed to be touchiing the web config file much anymore
and using the whole Website Configuration Wizard.

Can anyone explain how this new concept works? Where do I now stick my db
connection string and how to I access it? Where is it stored? It also talks
about roles/permissions in the Conciguration wizard. Does that refer to
users of the application I'm building? Do I no longer create my own forms/db
tables to maintain users with admin login priviliges?

-Darrel
 
K

Ken Cox - Microsoft MVP

You're not obligated to use the tool. If you add your own configuration
elements, the wizard will pick them up the next time you run it.

Here are some examples and links that should get you going:

Access:

<configuration>
<appSettings/>
<connectionStrings>
<add name="blrpConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\blrp.mdb;Persist Security Info=True"
providerName="System.Data.OleDb"/>
</connectionStrings>
<system.web>


SQLExpress
<connectionStrings>
<add
name="LocalSqlServer"
connectionString="data source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User
Instance=true"
providerName="System.Data.SqlClient"
/>
</connectionStrings>


Storing and Retrieving Connection Strings

http://msdn2.microsoft.com/en-us/library/ms254494(VS.80).aspx
 
D

Darrel

You're not obligated to use the tool. If you add your own configuration
elements, the wizard will pick them up the next time you run it.

Here are some examples and links that should get you going:

Thanks, Ken! That was simple once I knew. You'd think that if VS.net can
tell you something is deprecated, it could also give you a hit as to what to
replace it with ;o)

I noticed that my DB connection string is now considered a
ConnectionStringSettings but not a 'string'. Can I still pass a
ConnectionString Setting when using DB calls as a string? (Of course, I
realize that DB connections are now written differently in 2.0 so maybe
that'll make sense when I tackle that next...)

-Darrel
 
G

Guest

try something like this when you first get your connectionstring from your
web.config

Dim connectionStrings As _
ConnectionStringSettingsCollection = _
ConfigurationManager.ConnectionStrings

Dim myConnString As String =
connectionStrings("yourconnectionstringname").ConnectionString


then pass myConnString to whatever subs or functions you need

hope that makes sense
 
E

Erik Funkenbusch

Thanks, Ken! That was simple once I knew. You'd think that if VS.net can
tell you something is deprecated, it could also give you a hit as to what to
replace it with ;o)

Normally you would use the wizard to create the connections string. When
you drop a SqlDataSource onto your form, you can then click the wizards and
it will create the string for you.
I noticed that my DB connection string is now considered a
ConnectionStringSettings but not a 'string'. Can I still pass a
ConnectionString Setting when using DB calls as a string? (Of course, I
realize that DB connections are now written differently in 2.0 so maybe
that'll make sense when I tackle that next...)

..ToString() is your friend.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top