DSN per connection string?

We have an ASP.NET website that uses a database in which we want to use a connection string to reach it. We have successfully created a DSN to connect to this database, but I can’t find the correct magic to go with the connection string.

Is there an easy way to translate values ​​from a DSN to a connection string? I know that from the user interface there is no obvious answer to this question ... each db provider provides a different interface for creating a DSN based on what they need. However, I was hoping that under the user interface, this could just do something like creating a connection string backstage, and I could look at that to see what I'm doing wrong. Any hope of that? If so, what pointers to information do I need?

(I went to connectionstrings.com to make sure my connection string is in the correct format, but nothing works ... that's why I'm trying to make this weird translation from-dsn clock.)

EDIT: Something I shouldn't have talked about is that we don’t want to have a DSN record. We have created it and used it for now, but we want to get rid of it and use connectionstring without a dsn.

+3
source share
4 answers

If you can use OLEDB, you can create a file

+5
source

If you created a DSN, then the DSN is ConnectionString!

You can simply use DSN=<YourDSNName>and pass it to the OdbcConnection object.

For example, using C #:

string dsnName = "DSN=MyDSN";
using (OdbcConnection conn = new OdbcConnection(dsnName))
{
  conn.Open();
}

Alternatively, you can use the class OdbcConnectionStringBuilderand set its property DSN.

+4

Mark Brackett : 32- ODBC 64- Windows - HKLM\Software\Wow6432Node\ODBC\ODBC.INI\

+3

In my case, this was enough:

  • Delete title
  • Replace all new lines with a comma
  • Use curly braces as a group separator

Here is my DSN file created by the ODBC data source administrator (3rd tab DSN file)

[ODBC]
DRIVER=MySQL ODBC 5.3 ANSI Driver
UID=MyUserName
PORT=3306
DATABASE=mydatabasename
SERVER=localhost

And here is what my connection string looks like:

DRIVER={MySQL ODBC 5.3 ANSI Driver};UID=MyUserName;PORT=3306;DATABASE=mydatabasename;SERVER=localhost
0
source

Source: https://habr.com/ru/post/1710697/


All Articles