Solved

Using a DSN in App.config under <appsettings>

Posted on 2010-09-13
7
882 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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