473,671 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Dat aSet
Dim connectionStrin g As String = "Provider=Micro soft.Jet.OLEDB. 4.0;
Ole DB Services=-4; Data Source=C:\Datab ase\myDatabase. mdb"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Ole Db.OleDbConnect ion(connectionS tring)
Dim queryString As String = "SELECT [t_news].* FROM [t_news]"
Dim dbCommand As System.Data.IDb Command = New
System.Data.Ole Db.OleDbCommand
dbCommand.Comma ndText = queryString
dbCommand.Conne ction = dbConnection
Dim dataAdapter As System.Data.IDb DataAdapter = New
System.Data.Ole Db.OleDbDataAda pter
dataAdapter.Sel ectCommand = dbCommand
Dim dataSet As System.Data.Dat aSet = New System.Data.Dat aSet
dataAdapter.Fil l(dataSet)
Return dataSet
End Function

Shouldn't I move the connection,
connectionStrin g As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Ole DB
Services=-4; Data Source=C:\Datab ase\myDatabase. mdb"

to my Web.config file?

Can someone tell me how can I do this?

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

There are several recommended ways to do this. One of them (at least the
initial step towards a better workday) is to put connectionstrin g info in
web.config. You can do this by adding the element <appSettings> to your
web.config between the <configuratio n> 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.Configur ation.Configura tionSettings class later.
Here's an example:

In your web.config:

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

In your code:

string connStr =
System.Configur ation.Configura tionSettings.Ap pSettings.Get(" connStr");

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

HTH,
Lars-Erik

"Shapper" <mdmoura*NOSPAM *@gmail.*DELETE 2SEND*com> wrote in message
news:eT******** *****@TK2MSFTNG P12.phx.gbl...
Hello,

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

Function dsNews() As System.Data.Dat aSet
Dim connectionStrin g As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Ole
DB Services=-4; Data Source=C:\Datab ase\myDatabase. mdb"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Ole Db.OleDbConnect ion(connectionS tring)
Dim queryString As String = "SELECT [t_news].* FROM [t_news]"
Dim dbCommand As System.Data.IDb Command = New
System.Data.Ole Db.OleDbCommand
dbCommand.Comma ndText = queryString
dbCommand.Conne ction = dbConnection
Dim dataAdapter As System.Data.IDb DataAdapter = New
System.Data.Ole Db.OleDbDataAda pter
dataAdapter.Sel ectCommand = dbCommand
Dim dataSet As System.Data.Dat aSet = New System.Data.Dat aSet
dataAdapter.Fil l(dataSet)
Return dataSet
End Function

Shouldn't I move the connection,
connectionStrin g As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Ole DB
Services=-4; Data Source=C:\Datab ase\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******@newsg roup.nospam> wrote in message
news:la******@n ewsgroup.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 connectionstrin g info in
web.config. You can do this by adding the element <appSettings> to your
web.config between the <configuratio n> 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.Configur ation.Configura tionSettings class later.
Here's an example:

In your web.config:

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

In your code:

string connStr =
System.Configur ation.Configura tionSettings.Ap pSettings.Get(" connStr");

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

HTH,
Lars-Erik

"Shapper" <mdmoura*NOSPAM *@gmail.*DELETE 2SEND*com> wrote in message
news:eT******** *****@TK2MSFTNG P12.phx.gbl...
Hello,

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

Function dsNews() As System.Data.Dat aSet
Dim connectionStrin g As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Ole
DB Services=-4; Data Source=C:\Datab ase\myDatabase. mdb"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Ole Db.OleDbConnect ion(connectionS tring)
Dim queryString As String = "SELECT [t_news].* FROM [t_news]"
Dim dbCommand As System.Data.IDb Command = New
System.Data.Ole Db.OleDbCommand
dbCommand.Comma ndText = queryString
dbCommand.Conne ction = dbConnection
Dim dataAdapter As System.Data.IDb DataAdapter = New
System.Data.Ole Db.OleDbDataAda pter
dataAdapter.Sel ectCommand = dbCommand
Dim dataSet As System.Data.Dat aSet = New System.Data.Dat aSet
dataAdapter.Fil l(dataSet)
Return dataSet
End Function

Shouldn't I move the connection,
connectionStrin g As String = "Provider=Micro soft.Jet.OLEDB. 4.0; Ole DB
Services=-4; Data Source=C:\Datab ase\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
7760
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 ---------------------------------------------------------------------------- ----------------- import re, os, time, shutil os.chdir(os.environ+os.environ+"\\Desktop") DESKTOP = os.listdir(os.environ+os.environ+"\\Desktop")
7
13960
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 new file: (I have removed most of the logic of the code here, so I am not sure it's going to be helpful)
2
1219
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 like this: <Connection> <DEV>........ </DEV> <LIVE>....... </LIVE </Connection>
7
4729
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 following for the command-line arguments: java -jar sforcedataloader.jar -Dsalesforce.config.dir=CONFIG_DIRECTORY They also give an example:
1
2759
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" value="server=Server;database=DB;uid=name;pwd=p"/> </appSettings>
8
2387
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 buggy or that you should create a new folder then copy the content of the old into it and then delete the old one...pretty lame for such a simple IO action. Can microsoft give an answer to how to fix this or is this just a know bug... that will...
10
3077
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 config does specify a machinekey setting: <machineKey validationKey="447C05E8B3A71401CC4CAE5513A7F1A3494A3618EE819316AAD1D58433F236A759D66FB4154500E01EB4E1BC1DE42046E2D652D391CB8367A1649438867A02EB"...
0
3013
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 asp.net client page that called it. I moved the whole app to a test server, & when I try to run it, I get the error "No connection could be made because the target machine actively refused it". It looks like the wsdl still points to my laptop...
0
1379
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 factory and interface definition in a single assembly. The class factory will instantiate the correct adapter for communication with a mobile device at runtime. We're doing it this way because we won't know which cellular network we're communicating over...
0
8401
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8824
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8603
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8673
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6236
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5703
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2060
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.