Using DSN in connection string

M J 661 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.

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,251 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,234 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 25,471 Reputation points Microsoft Vendor
    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