Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How to get the connection string value from hibernate. Ask Question. Asked 11 years, 10 months ago. Active 11 years, 10 months ago. Viewed 8k times. Add "hbm2ddl. I've tried use NHibernate. ConnectionString, but it didn't work. How can I get this? Thank you. Top Rated Most Recent. Accept Solution Reject Solution. You should have googled a bit.
You even can find the sample code in the following MSDN link. Add your solution here. OK Paste as. Treat my content as plain text, not as HTML. Existing Members Sign in to your account. This email is in use. Do you need your password? Submit your solution! Now we will see the next way to specify a connection. Now I will create a common class file with connection code. I have created a DBConnectionClass. You can use this class file in multiple Web applications where you need to use the same database connection.
In this class I declared an enum for the list of the database. We can specify all the database names to be used across application and access them using an enum.
Then I wrote a method, GetConnectionstring, with Database enum parameter. Write the following code in your class:. Then I will describe how to access this class method in a web page. You can call this method as in DBConnectionClass. Getconnectionstring DBConnectionClass.
In the same way you saw in the web. This example demonstrates how to retrieve a connection string from a configuration file by specifying its name. The code creates a ConnectionStringSettings object, matching the supplied input parameter to the ConnectionStrings name.
If no matching name is found, the function returns null Nothing in Visual Basic. This example demonstrates how to retrieve a connection string by specifying the provider name in the format Microsoft. The code iterates through the ConnectionStringSettingsCollection and returns the connection string for the first ProviderName found. If the provider name is not found, the function returns null Nothing in Visual Basic.
NET 2. Although primarily designed for ASP. NET, protected configuration can also be used to encrypt configuration file sections in Windows applications. For a detailed description of the protected configuration capabilities, see Encrypting Configuration Information Using Protected Configuration.
The following configuration file fragment shows the connectionStrings section after it has been encrypted. The configProtectionProvider specifies the protected configuration provider used to encrypt and decrypt the connection strings. The EncryptedData section contains the cipher text. When the encrypted connection string is retrieved at run time, the. NET Framework uses the specified provider to decrypt the CipherValue and make it available to your application.
You do not need to write any additional code to manage the decryption process. Protected configuration providers are registered in the configProtectedData section of the machine. The values shown here have been truncated for readability. You can configure additional protected configuration providers by adding them to the machine. You can also create your own protected configuration provider by inheriting from the ProtectedConfigurationProvider abstract base class.
The following table describes the two configuration files included with the. Both providers offer strong encryption of data. However, if you are planning to use the same encrypted configuration file on multiple servers, such as a Web farm, only the RsaProtectedConfigurationProvider enables you to export the encryption keys used to encrypt the data and import them on another server.
The System. Configuration namespace provides classes to work with configuration settings programmatically. The ConfigurationManager class provides access to machine, application, and user configuration files. If you are creating an ASP. NET application, you can use the WebConfigurationManager class, which provides the same functionality while also allowing you to access settings that are unique to ASP. Cryptography namespace contains classes that provide additional options for encrypting and decrypting data.
Use these classes if you require cryptographic services that are not available using protected configuration. Some of these classes are wrappers for the unmanaged Microsoft CryptoAPI, while others are purely managed implementations.
0コメント