Ways and best practices for connecting to SQL

Therefore, usually I just put my sql connection string in my asp.net web.config and refer to it whenever I need to open a database connection, however this leaves me with a link to it throughout my project. It also provides my username and password for sql connection in my web.config if it is not encoded.

What are the best practices for maintaining join methods in a class or class library? I saw a php tutorial that did this very well (but I can't find it again) and allowed reuse.

+3
source share
2 answers

I will always store the connection string in web.config, as the connections between servers and databases can always change, even if they are not shared. To make it easier to view in code, you can always add something like this:

String m_Connection = ConfigurationManager.AppSettings["MyConnectionString"];

and then just link m_Connectioneverywhere.

I would also always encrypt the connection string using EncryptionProvider.

Great MSDN Article: How to: Encrypt Configuration Sections in ASP.NET 2.0 Using DPAPI

+5
source

@gillyb. web.config () . spring.Net, . , , , Spring.config, , web.config.

0

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


All Articles