Using DSN in connection string

M J 681 Reputation points
2021-10-19T22:26:11.837+00:00

I saw this article odbc-dsn-using-in-Asp-Net on using DSN in connection strings and then found this page system.data.odbc.odbcconnection.connectionstring. I would prefere to use the DSN in the connectionstring as that is something that is common across both our development and production servers. Plus it does not give a path or computername if someone is able to open the Web.config file.

I set it up like so in the Web.config

<configuration>  
  <connectionStrings>  
     <add name="JobDatabase" connectionString="Dsn=JobDatabase" providerName="System.Data.Odbc" />   
  </connectionStrings>  
</configuration>  

However, when I try to run I get this runtime error

Keyword not supported: 'dsn'.

I also tried as

<configuration>  
      <connectionStrings>  
         <add name="JobDatabase" connectionString="Dsn=JobDatabase" providerName="System.Data.SqlClient" />   
      </connectionStrings>  
    </configuration>  

That produced the same runtime error.
I am working in Visual Studio 2019

Any assistance on this would be appreciated.

Developer technologies ASP.NET Other
Developer technologies C#
{count} votes

Accepted answer
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2021-10-20T05:22:32.92+00:00

    Hi @M J ,
    First, if you want to use ODBC DSN, your connection string must use System.Data.Odbc.
    Secondly, DSN refers to your data source, have you configured it correctly in the Windows OBDC manager.
    Finally, you need to confirm whether the connection object in the code is ODBCConnection.
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.