对一段SQL进行语法检查
2010-03-16 22:26
323 查看
下面的C#代码用来检查一段SQL语句的语法是否正确:
public string CheckSQLCommand(string connectionString, string sql) { String message = null; try { using (SqlConnection sqlConnection = new SqlConnection(connectionString)) { sqlConnection.Open(); SqlCommand sqlCommand = sqlConnection.CreateCommand(); sqlCommand.CommandTimeout = 1; sqlCommand.CommandText = "SET PARSEONLY ON;" + sql + ";SET PARSEONLY OFF;"; sqlCommand.ExecuteNonQuery(); } } catch (Exception ex) { if (ex.Message.IndexOf("Timeout") == -1) { SqlException sqlException = ex as SqlException; if (sqlException != null) { if (sqlException.Number < 50000 && sqlException.Number != 2627) { message = ex.Message; } } } } return message; }
相关文章推荐
- ABAP--使用SLIN事务码进行ABAP程序扩展语法检查,提高程序开发的质量
- Sql 语法检查
- 使用T-SQL进行数据库备份并检查该备份文件是否存在且作出相应处理
- 检查sql字符串中是否有单引号,有则进行转化
- 检查指定表的当前标识值,如有必要,还对标识值进行更正。【重置sql自动增长列】
- ABAP--使用SLIN事务码进行ABAP程序扩展语法检查,提高程序开发的质量
- Microfoft Office Word 无法对这篇文档进行拼写或语法检查
- 写了一个PHP版本的MONGODB语法解析器,可以通过类似SQL的语法来进行MONGODB的查询,不知道有人需要不,分享一下吧
- 巧用SQL的with语法生成临时结果集,进行查询与更新同步操作,解决高并发下对数据的重复访问
- ABAP--使用SLIN事务码进行ABAP程序扩展语法检查,提高程序开发的质量
- 使用or展开进行sql优化(即sql语法union all代替or可以提高效率)
- 浏览器兼容性问题,为什么同一段JavaScript代码,不同浏览器上为什么会产生不同效果,甚至bug?浏览器不就是严格按照JavaScript语法进行的吗?java代码为什么从来没听过有什么兼容问题?
- 快捷方便的对js文件进行语法检查。
- 使用sql语法跨多个excel文件进行查询工具
- ABAP--使用SLIN事务码进行ABAP程序扩展语法检查,提高程序开发的质量
- golang使用vet进行语法检查
- ABAP--使用SLIN事务码进行ABAP程序扩展语法检查,提高程序开发的质量
- C#检查sql语法正确性
- 简单的证明预编译不进行语法检查
- Set noexec on 与 Set parseonly on的区别及SQL语法检查