Connection string in UDL-file

  • Thread starter Thread starter Christian Pické
  • Start date Start date
C

Christian Pické

Hi,

I want to store my connection parameters in a UDL-file. The building of the
file was easy, but I can't use the file. In an example I found this:

myConnection.ConnectionString = "File Name=GenesisNET.udl";

but when I try to open the connection I get this error message:

An unhandled exception of type 'System.ArgumentException' occurred in
genesisbl.dll
Additional information: Keyword not supported: 'file name'.

Can anyone provide me the right syntax to use the UDL-file?
TIA
Christian
 
Christian,

SqlClient does not permit reading of connection strings from files in this
manner. Even if it did, you could not use an OLE DB connection string since
you cannot pass the Provider parameter to SqlClient. The OleDbConnection
object does allow for use of a UDL file for specifying the connection string
(see
http://msdn.microsoft.com/library/e...OleDbConnectionClassConnectionStringTopic.asp),
but this alone is not a good enough reason to use OleDb rather than
SqlClient if you are working exclusively against SQL Server. Perhaps there
is somewhere else you can store your connection string.

HTH,
Nicole
 
OK, Nicole, I see 2 more acceptable ways to store the connection string:

1. Using a App.config (I hope it works like the Web.config I use in
ASP.NET).

2. Storing it in the Windows Registry.

On your oppinion, what is the best way (it is for a distributed
CRM-application (3-thier))? Or do you have other suggestions?

Kind regards,
Christian
 
Hi,
SqlClient does not support UDL files. please refer the .NET Data
Access Architecture Guide in Microsoft Patterns page in Page Number 16.
" In a Universal Data Link (UDL) file (supported only by the OLE
DB .NET Data Provider)"

Thanks And Regards

Madhanmohan S
 
See inline...


Christian Pické said:
OK, Nicole, I see 2 more acceptable ways to store the connection string:

1. Using a App.config (I hope it works like the Web.config I use in
ASP.NET).
If your connection string contains credentials (as opposed to using
integrated security), you should definitely consider encrypting it if you do
this. A Google search on the following terms will show you several ways to
accomplish this:

"web.config" "connection string" encrypt

2. Storing it in the Windows Registry.
An even better idea than the web.config file since it ensures that the
connection string, encrypted or not, can never be downloaded from you site,
even if the .config ISAPI mapping is somehow removed or altered. However,
you should still consider encrypting it if it contains credentials since any
user with permissions to read the registry key will be able to read it if
they can get access to the machine registry.

See the "Storing Connection Strings" section of
http://msdn.microsoft.com/library/en-us/dnbda/html/daag.asp for discussion
of the various pro and cons of different approaches.
On your oppinion, what is the best way (it is for a distributed
CRM-application (3-thier))? Or do you have other suggestions?

In a "pure" multi-tier application, your UI tier (the web application)
should never be communicating directly with the database, so it shouldn't
need to deal with connection strings at all. Depending on the exact
architecture of your application, it is either (one of) the business tier(s)
or the data access layer that would need to be able to retrieve the
connection string. There are various ways of handling this, including using
integrated security, but they are very dependant on the details of your
particular application.

See http://msdn.microsoft.com/library/en-us/dnbda/html/BOAGag.asp for a
general discussion of handling data within a multi-tier application.
 
Back
Top