Solved

Using a DSN in App.config under <appsettings>

Posted on 2010-09-13
7
885 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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