2010-03-11 124 views

回答

3

对密码和/或连接字符串使用加密,并将加密的密码/连接字符串存储在某种配置文件中。然后用我的答案在这里对其进行解密后的连接字符串值添加到NHibernate的配置对象:

How to load application settings to NHibernate.Cfg.Configuration object?

像:

nHibernateConfiguration.SetProperty( 
    NHibernate.Cfg.Environment.ConnectionString, 
    Util.Decrypt(encryptedConnectionString)); 
2

一般来说,如果您要连接到使用sql登录说一个sql server数据库,除非您决定使用Windows身份验证,那么您将输入一个密码。

<connectionStrings><add name="MyDbConn1" 
     connectionString="Server=MyServer;Database=MyDb;Trusted_Connection=Yes;"/> 
<add name="MyDbConn2" 
     connectionString="Initial Catalog=MyDb;Data Source=MyServer;Integrated Security=SSPI;"/> 
</connectionStrings> 

您应该锁定SQL Server登录可以执行的权限/角色。

如果必须使用SQL Server风格的登录,你可以加密这样的密码..

Encrypting Connection String in web.config

或其他一些链接..

http://www.kodyaz.com/articles/Encrypting-in-web-configuration-file.aspx

http://www.codeproject.com/KB/cs/Configuration_File.aspx

http://www.velocityreviews.com/forums/t84120-how-to-encrypt-database-password-in-web-config-file.html

编辑:

要在web.config文件中的ConnectionString元素中使用一个连接字符串,那么这说明你..

http://www.martinwilley.com/net/code/nhibernate/appconfig.html

或者

使用fluentnhibernate。 :)

相关问题