如何从hibernate.cfg.xml文件获取连接字符串值?(How to get the connection string value from hibernate.cfg.xml file?)
我使用Fluent NHibernate,并需要从hibernate.cfg.xml文件的connection.connection_string属性中获取我的连接字符串来创建我的Session Factory:
private static ISessionFactory SessionFactory { get { return = Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString(c => c.FromConnectionStringWithKey("MyConnStr"))) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<FooMap>()) .ExposeConfiguration(c => c.Properties.Add("hbm2ddl.keywords", "none")) .BuildSessionFactory(); } }
我想从hibernate.cfg.xml文件中替换连接字符串的MyConnStr(即在我的web.config文件中)“ c => c.FromConnectionStringWithKey(”MyConnStr“) ”。
我试过使用NHibernate.Cfg.Environment.ConnectionString,但它没有工作。
我怎样才能得到这个?
谢谢。
I'm using Fluent NHibernate and need to get my Connection String from the connection.connection_string property on hibernate.cfg.xml file to create my Session Factory:
private static ISessionFactory SessionFactory { get { return = Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString(c => c.FromConnectionStringWithKey("MyConnStr"))) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<FooMap>()) .ExposeConfiguration(c => c.Properties.Add("hbm2ddl.keywords", "none")) .BuildSessionFactory(); } }
I want to replace MyConnStr (that is in my web.config file) "c => c.FromConnectionStringWithKey("MyConnStr")" for the connection string from the hibernate.cfg.xml file.
I've tried use NHibernate.Cfg.Environment.ConnectionString, but it didn't work.
How can I get this?
Thank you.
原文:https://stackoverflow.com/questions/2432628
最满意答案
您需要使用查询参数,否则您很容易受到SQL注入攻击。 永远不要相信客户。 任何心怀不满的员工都可能对您的数据造成严重损害。
You need to use query parameters or else you are vulnerable to SQL injection attacks. Never trust the client. Any disgruntled employee could cause serious damage to your data.
相关问答
更多-
你可以通过$ _POST []数组获取html发布数据到这个php文件的日期。 例如: $date=$_POST["userDate"]; 通过假设该值为: '01-01-2012' 你必须改变你的查询为: $sql="SELECT dispatch_1.site_id, dispatch_1.status_1, dispatch_1.created_on, FROM fpscdb001_ws_001.dispatch_1 WHERE DATE(dispatch_1.e ...
-
从JavaScript中的用户输入生成复杂的文本模板(Generating complex text templates from user input in JavaScript)[2022-07-22]
一种方法是使用JSON创建数据模型。 您的UI更新数据模型中的值,然后在每次更改后输出整个内容。 这样你就可以跳过很多逻辑。 jQuery模板可以帮助实现这个目的: One way to do this is to have a data model using JSON. Your UI updates the values in the data model, then you output the whole thing after every change. This way you can ski ... -
根据用户输入生成子系统(MATLAB / SimMechanics)(Generating sub-systems based on user input (MATLAB/SimMechanics))[2022-05-28]
是的,你可以自动化它,只要你知道什么是susbsytems和你想要添加什么关节。 感兴趣的功能是: add_block (path_to_your_subsystem,path_to_destination_subsystem) (我假设你的susbsystem存储在一个库中)。 您可能希望指定“位置”参数,以便所有块不会彼此重叠。 需要进行一些实验才能找到适用于您的模型的坐标,并根据要添加的susbystems数量进行参数化。 add_line (path_to_subsystem_of_interest ... -
根据用户输入编译动态ADODB SQL语句的最佳方法(Best way to compile a dynamic ADODB SQL Statement based on user input)[2022-04-26]
我不完全确定我理解你在问什么,但是使用4 if语句的另一种方法是将它们包含在你的SQL语句中: SELECT * FROM TABLE WHERE (PREFIX = a OR a = '') AND (LASTNAME = d OR d = '') AND (MIDDLENAME = c OR c = '') AND (FIRSTNAME = b OR b = '') 这样,如果值为空,则不会搜索它们。 Not completely sure I understan ... -
您需要使用查询参数,否则您很容易受到SQL注入攻击。 永远不要相信客户。 任何心怀不满的员工都可能对您的数据造成严重损害。 请参阅: 如何在MS Access 2003中创建参数化查询,并使用其他查询/表单填充参数并获取结果集 You need to use query parameters or else you are vulnerable to SQL injection attacks. Never trust the client. Any disgruntled employee could c ...
-
查尔斯几乎得到了正确的答案。 它应该是: SELECT * FROM MyTable (NOLOCK) WHERE col1 = 'ABC' AND (@checked = 0 OR col2 LIKE '%XYZ%') 这是SQL中用于条件谓词的经典“模式”。 如果@checked = 0 ,那么它将返回与谓词的其余部分匹配的所有行( col1 = 'ABC' )。 SQL Server甚至不会处理OR后半部分。 如果@checked = 1那么它将评估OR的第二部分并返回匹配col1 = 'A ...
-
你可以试试这个吗?如果您希望获得所有参数的值,则可以使用COALESCE()执行以下操作: $query = "SELECT * FROM sales INNER JOIN party ON sales.party_id = party.party_id INNER JOIN items ON sales.item_no = items.item_no WHERE inv_date >= ? AND inv_date <= ? AND payment_type = COAL ...如果不写出所有内容,那就是这个想法: 声明空变量: int UserId = 0; string userName = ""; 用您的数据填充变量(假设您正在使用函数?): private void function(int id, string name, ...further params...) { int UserId = 0; string userName = ""; UserId = (id!=null) ? id : 0; /*Shorthand if state ...假设表中的所有字段名称与表单输入的名称相同,这是直截了当的。 你可以用这个: $query = "UPDATE product SET"; $comma = " "; foreach($_POST as $key => $val) { if( ! empty($val)) { $query .= $comma . $key . " = '" . mysql_real_escape_string(trim($val)) . "'"; $comma = ", "; ...
相关文章
更多- Hadoop HDFS Wrong FS: hdfs:/ expected file:///
- 怎么得到String数组?
- Java 流(Stream)、文件(File)和IO
- There is already an open DataReader associated with this Connection which must be closed first
- 移动MM failed to find resource file{mmiap.xml}
- 无法启动Hbase hbase-default.xml file seems to be for and old version of HBase
- Java String类
- redis 字符串(String) SET 操作
- Hadoop master connection reset by peer resolution
- 用‘button’跟‘text’组合代替‘file’,选择文件后点‘submit’,‘file’的值被清空
最新问答
更多- 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
- 如何打破按钮上的生命周期循环(How to break do-while loop on button)
- C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
- 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
- 如何并排放置两个元件?(How to position two elements side by side?)
- 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
- 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
- Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
- 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
- 电脑高中毕业学习去哪里培训
- 电脑系统专业就业状况如何啊?
- IEnumerable
linq表达式(IEnumerable linq expressions) - 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
- Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
- 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
- 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
- 的?(The ? marks in emacs/haskell and ghc mode)
- 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
- 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
- 悬停时的图像转换(Image transition on hover)
- IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
- 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
- java分布式框架有哪些
- Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
- PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
- 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
- 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
- typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
- 武陟会计培训类的学校哪个好点?
- 从链接中删除文本修饰(Remove text decoration from links)