Storing Connection strings
Số trang: 6
Loại file: pdf
Dung lượng: 32.54 KB
Lượt xem: 4
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
[ Team LiB ] Recipe 1.12 Storing Connection Strings Problem You need to choose the best place to store connection strings that you need in your application to increase maintainability, simplify future modifications, and eliminate the need to recompile the application when it is modified.
Nội dung trích xuất từ tài liệu:
Storing Connection strings[ Team LiB ]Recipe 1.12 Storing Connection StringsProblemYou need to choose the best place to store connection strings that you need in yourapplication to increase maintainability, simplify future modifications, and eliminate theneed to recompile the application when it is modified.SolutionThere are several alternatives for storing connection strings, including hard-coding theconnection string in your application, storing it in an application configuration file or theWindows Registry, representing it using a Universal Data Link (UDL) file, or in a customfile.DiscussionA connection string is made up of a semi-colon delimited collection of attribute/valuepairs that define how to connect a data source. Although connection strings tend to looksimilar, the available and required attributes are different depending on the data providerand on the underlying data source. There are a variety of options providing differingdegrees of flexibility and security.Persist Security InfoThe Persist Security Info connection string attribute specifies whether the datasource can hang on to, or persist, sensitive information such as userauthentication credentials. Its value should be kept at the default false. If itsvalue is true, the connection information—including the password—can beobtained by querying the connection, allowing an untrusted party to have accessto sensitive information when a Connection is passed or persisted to a disk. Thisis an issue only when passing connected objects such as Connection orDataAdapter; disconnected objects such as DataSet and DataTable do not storeinformation about the original source of their data.Before a data source object is initialized for the first time, sensitive informationcan be retrieved from it regardless of the setting of the Persist Security Infoproperty. Avoid passing uninitialized data source objects.The Persist Security Info connection string attribute is supported by the SQLServer, OLE DB, and Oracle .NET Framework data providers. Although notsupported by the ODBC .NET Framework data provider, its behavior is as ifPersist Security Info is false and cannot be changed. Check the documentationfor other data providers to determine specific implementation details.Connecting to a database server requires passing credentials—username and password—to the server in a connection string. These credentials, together with the data sourcename, need to be kept private to protect unauthorized access to the data source. There aretwo approaches for obtaining these credentials: • Prompting for connection credentials at runtime. • Storing predetermined connection credentials on the server and using them at runtime to connect to the database server.Integrated SecurityIntegrated security is the most secure way to connect to a SQL Server andshould be used unless it is impractical to do so. Integrated security uses theidentity of the current active user rather than an explicit user ID and passwordin the connection string to authorize access to the database. Integrated securityavoids storing usernames and passwords in connection strings and its use isrecommended where possible instead of SQL Server Authentication.To use integrated security in the connection string, specify the value SSPI forthe Integrated Security attribute and do not specify User ID and Passwordconnection string attributes:Integrated Security=SSPISee Recipe 1.8 for information about connecting to SQL Server usingintegrated security from ASP.NET.Often, it is not practical to prompt for connection credentials because of disadvantagesincluding:Security Transferring connection information from the browser to the server can expose connection credentials if they are not encrypted.Connection pooling Each user must be recognized separately by the server. This does not allow effective connection pooling and can limit the scalability of the application. For more on connection pooling, see Recipe 1.15.Single sign-on It is difficult to integrate with single sign-on strategies, which are becoming increasingly important in enterprise environments (for example, where numerous applications are aggregated into portals).Server applications Cannot be used by applications that otherwise have no user interface, such as an XML web service.There are a number of techniques that you can use to store predetermined connectioncredentials. These, together with their advantages and drawbacks, are discussed in thefollowing subsections. Always configure predetermined accounts with the minimum permissions required. Never use sa or any other administrative account. Never use blank passwords.Hardcode in the applicationAn obvious technique for storing connection strings is hardcoding them into theapplication. Although this approach results in the best performance, it has poorflexibility; the application needs to be recompiled if the connection string needs to bechanged for any reason. Security is poor. The code can be disassembled to exposeconnection string information. Caching techniques together with external storagetechniques eliminate nearly all performance benefits of hardcoding over external storagetechniques.Hardcoding connection string information is not advised; external server-side storage ispreferred in nearly all cases because of the increased flexibility, security, andconfiguration ease. A discussion of available external storage options follows.Application configuration fileAn application configuration file is an XML-based text file that is used to storeapplication-specific settings used at runtime by the application. The naming conventionfor and deployment location of the file depend on the type of application:Exe ...
Nội dung trích xuất từ tài liệu:
Storing Connection strings[ Team LiB ]Recipe 1.12 Storing Connection StringsProblemYou need to choose the best place to store connection strings that you need in yourapplication to increase maintainability, simplify future modifications, and eliminate theneed to recompile the application when it is modified.SolutionThere are several alternatives for storing connection strings, including hard-coding theconnection string in your application, storing it in an application configuration file or theWindows Registry, representing it using a Universal Data Link (UDL) file, or in a customfile.DiscussionA connection string is made up of a semi-colon delimited collection of attribute/valuepairs that define how to connect a data source. Although connection strings tend to looksimilar, the available and required attributes are different depending on the data providerand on the underlying data source. There are a variety of options providing differingdegrees of flexibility and security.Persist Security InfoThe Persist Security Info connection string attribute specifies whether the datasource can hang on to, or persist, sensitive information such as userauthentication credentials. Its value should be kept at the default false. If itsvalue is true, the connection information—including the password—can beobtained by querying the connection, allowing an untrusted party to have accessto sensitive information when a Connection is passed or persisted to a disk. Thisis an issue only when passing connected objects such as Connection orDataAdapter; disconnected objects such as DataSet and DataTable do not storeinformation about the original source of their data.Before a data source object is initialized for the first time, sensitive informationcan be retrieved from it regardless of the setting of the Persist Security Infoproperty. Avoid passing uninitialized data source objects.The Persist Security Info connection string attribute is supported by the SQLServer, OLE DB, and Oracle .NET Framework data providers. Although notsupported by the ODBC .NET Framework data provider, its behavior is as ifPersist Security Info is false and cannot be changed. Check the documentationfor other data providers to determine specific implementation details.Connecting to a database server requires passing credentials—username and password—to the server in a connection string. These credentials, together with the data sourcename, need to be kept private to protect unauthorized access to the data source. There aretwo approaches for obtaining these credentials: • Prompting for connection credentials at runtime. • Storing predetermined connection credentials on the server and using them at runtime to connect to the database server.Integrated SecurityIntegrated security is the most secure way to connect to a SQL Server andshould be used unless it is impractical to do so. Integrated security uses theidentity of the current active user rather than an explicit user ID and passwordin the connection string to authorize access to the database. Integrated securityavoids storing usernames and passwords in connection strings and its use isrecommended where possible instead of SQL Server Authentication.To use integrated security in the connection string, specify the value SSPI forthe Integrated Security attribute and do not specify User ID and Passwordconnection string attributes:Integrated Security=SSPISee Recipe 1.8 for information about connecting to SQL Server usingintegrated security from ASP.NET.Often, it is not practical to prompt for connection credentials because of disadvantagesincluding:Security Transferring connection information from the browser to the server can expose connection credentials if they are not encrypted.Connection pooling Each user must be recognized separately by the server. This does not allow effective connection pooling and can limit the scalability of the application. For more on connection pooling, see Recipe 1.15.Single sign-on It is difficult to integrate with single sign-on strategies, which are becoming increasingly important in enterprise environments (for example, where numerous applications are aggregated into portals).Server applications Cannot be used by applications that otherwise have no user interface, such as an XML web service.There are a number of techniques that you can use to store predetermined connectioncredentials. These, together with their advantages and drawbacks, are discussed in thefollowing subsections. Always configure predetermined accounts with the minimum permissions required. Never use sa or any other administrative account. Never use blank passwords.Hardcode in the applicationAn obvious technique for storing connection strings is hardcoding them into theapplication. Although this approach results in the best performance, it has poorflexibility; the application needs to be recompiled if the connection string needs to bechanged for any reason. Security is poor. The code can be disassembled to exposeconnection string information. Caching techniques together with external storagetechniques eliminate nearly all performance benefits of hardcoding over external storagetechniques.Hardcoding connection string information is not advised; external server-side storage ispreferred in nearly all cases because of the increased flexibility, security, andconfiguration ease. A discussion of available external storage options follows.Application configuration fileAn application configuration file is an XML-based text file that is used to storeapplication-specific settings used at runtime by the application. The naming conventionfor and deployment location of the file depend on the type of application:Exe ...
Tìm kiếm theo từ khóa liên quan:
công nghệ thông tin kỹ thuật lập trình Oreilly Ado Dot Net Cookbook Ebook-Lib Storing Connection stringsGợi ý tài liệu liên quan:
-
52 trang 430 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 314 0 0 -
74 trang 299 0 0
-
96 trang 293 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 289 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 281 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 275 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 269 1 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 265 0 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 265 0 0