?
Solved

Using a DSN in App.config under <appsettings>

Posted on 2010-09-13
7
Medium Priority
?
902 Views
Last Modified: 2012-05-10
In the App.config file under <appsettings> how do I bind a DSN name to the value property.  

I have tried this

<appsettings>
<add key="keyname" value="DSN=dsnname;integrated security=true">
</appsettings>

I am getting an error "keyword dsn not supported".  I must use the DSN name as the server names may not be the same but the DSN will point to the correct server when the application is moved to the production environment.

I am using the .Net 4.0 Framework.
0
Comment
Question by:sherbug1015
  • 4
  • 2
7 Comments
 
LVL 21

Expert Comment

by:chapmanjw
ID: 33667004
Can you show the code you are using to access the data with this application setting (your c# or vb code)?
0
 

Author Comment

by:sherbug1015
ID: 33667498
Dim strConnection As String = ConfigurationSettings.AppSettings("IQSConn")
0
 
LVL 11

Expert Comment

by:lenordiste
ID: 33667544
the error you are getting is most probably coming from your database connection string: you need to add a provider name else the DNS keyword is detected has being invalid.

I think the best way to tackle this is to use the connectionStrings node like below (assuming you are using odbc):
<appSettings>
<connectionStrings>
<add name="IQSConn" connectionString="DSN=dsnname;integrated security=true"
providerName="System.Data.Odbc"/>
</connectionStrings>
</appSettings>
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:sherbug1015
ID: 33667574
I am getting an error that <connectionStrings> is not a child element of <appsettings>

0
 
LVL 11

Accepted Solution

by:
lenordiste earned 1500 total points
ID: 33667630
oups my bad; I typed too fast ! Here is the right structure:

<configuration>
  <appSettings>
   ....
  </appSettings>
   <connectionStrings>
       <add name="IQSConn" connectionString="DSN=dsnname;integrated security=true"
             providerName="System.Data.Odbc"/>
   </connectionStrings>
0
 

Author Comment

by:sherbug1015
ID: 33667672
OK  since I am no longer using Appsettings, like this
Dim strConnection As String = ConfigurationSettings.AppSettings("IQSConn")

How to I use the values between the <connectionString> tags

Dim strConnection as String = ????????


0
 

Author Closing Comment

by:sherbug1015
ID: 33677103
Expert would not complete the question.  
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question