473,386 Members | 1,795 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.

How to move this line to web.config?

Hello,

I have a dataset in an ASP.NET/VB web page:

Function dsNews() As System.Data.DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;
Ole DB Services=-4; Data Source=C:\Database\myDatabase.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )
Dim queryString As String = "SELECT [t_news].* FROM [t_news]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function

Shouldn't I move the connection,
connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4; Data Source=C:\Database\myDatabase.mdb"

to my Web.config file?

Can someone tell me how can I do this?

Thank You,
Miguel
Nov 19 '05 #1
2 1514
Hi!

There are several recommended ways to do this. One of them (at least the
initial step towards a better workday) is to put connectionstring info in
web.config. You can do this by adding the element <appSettings> to your
web.config between the <configuration> and <system.web> elements. Inside the
appSettings element you can define as many keys with string values as you
want and then access these with the
System.Configuration.ConfigurationSettings class later.
Here's an example:

In your web.config:

<configuration>
<appSettings>
<add key="connStr" value="Data Source=xx......"/> <!-- Full
connection string -->
</appSettings>
<system.web>
.....

In your code:

string connStr =
System.Configuration.ConfigurationSettings.AppSett ings.Get("connStr");

Et voilà :) You've made you'r app configurable..

HTH,
Lars-Erik

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:eT*************@TK2MSFTNGP12.phx.gbl...
Hello,

I have a dataset in an ASP.NET/VB web page:

Function dsNews() As System.Data.DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole
DB Services=-4; Data Source=C:\Database\myDatabase.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )
Dim queryString As String = "SELECT [t_news].* FROM [t_news]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function

Shouldn't I move the connection,
connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4; Data Source=C:\Database\myDatabase.mdb"

to my Web.config file?

Can someone tell me how can I do this?

Thank You,
Miguel

Nov 19 '05 #2
Thanks Lars.

"Lars-Erik Aabech" <la******@newsgroup.nospam> wrote in message
news:la******@newsgroup.nospam:
Hi!

There are several recommended ways to do this. One of them (at least the
initial step towards a better workday) is to put connectionstring info in
web.config. You can do this by adding the element <appSettings> to your
web.config between the <configuration> and <system.web> elements. Inside the
appSettings element you can define as many keys with string values as you
want and then access these with the
System.Configuration.ConfigurationSettings class later.
Here's an example:

In your web.config:

<configuration>
<appSettings>
<add key="connStr" value="Data Source=xx......"/> <!-- Full
connection string -->
</appSettings>
<system.web>
.....

In your code:

string connStr =
System.Configuration.ConfigurationSettings.AppSett ings.Get("connStr");

Et voilà :) You've made you'r app configurable..

HTH,
Lars-Erik

"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:eT*************@TK2MSFTNGP12.phx.gbl...
Hello,

I have a dataset in an ASP.NET/VB web page:

Function dsNews() As System.Data.DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole
DB Services=-4; Data Source=C:\Database\myDatabase.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString )
Dim queryString As String = "SELECT [t_news].* FROM [t_news]"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function

Shouldn't I move the connection,
connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4; Data Source=C:\Database\myDatabase.mdb"

to my Web.config file?

Can someone tell me how can I do this?

Thank You,
Miguel


Nov 19 '05 #3

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

Similar topics

1
by: bmgz | last post by:
I am have made a simple script that moves all desktop clutter (ie files that are not *.lnk) to a specified folder eg. c:\myhome\mydocs\desktopdebris\2003-12-16 ...
7
by: Stéphane Ninin | last post by:
Hello world, I am fighting with what is probably a stupid problem. In a wxpython GUI, here is a method which must read a file, and if the file is not correctly formed rename it and create a...
2
by: Steve | last post by:
I am trying to move my connection settings out to a config file, rather than having them hardcoded in my app. What is the best way of doing this? I created a simple xml doc that looked something...
7
by: Steve M | last post by:
I'm trying to invoke a Java command-line program from my Python program on Windows XP. I cannot get the paths in one of the arguments to work right. The instructions for the program describe the...
1
by: rehiaa | last post by:
How do I move my connction string from each page and instead refer to it from the web.config file? In Web.Config I have <appSettings> <add key="ConnectionString"...
8
by: Ron Vecchi | last post by:
I know this has been asked before but I out of all the posts I've read regarding using Directory.Move and then the application restarting itself I have found no answer except that Sessions are...
10
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web...
0
by: Orbit | last post by:
Hi, I hope someone could help me. I have a simple web service that I developed on my laptop that resides within a large web application. It queries Northwind & presents the data in a grid in the...
0
balabaster
by: balabaster | last post by:
Hi all, I'm creating a class factory and a bunch of adapters to allow in house applications to communicate with mobile applications over different cellular networks. I've got my class...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.