【发布时间】:2015-07-18 03:22:18
【问题描述】:
我是 sqlserver 的新手,我遇到了一个错误:
System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near ')'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolea
n breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception
, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObj
ect stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand
cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,
TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName,
Boolean async, Int32 timeout, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSou
rce`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean
asyncWrite)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at KellenTechnology.Program.Main(String[] args) in c:\Users\Mohit\Documents\V
isual Studio 2013\Projects\KellenTechnology\KellenTechnology\Program.cs:line 37
ClientConnectionId:d9ec7a79-87d2-40f9-83f9-dc7b08c05153
这个错误原因的代码是下面的连接字符串:
string sqlStatement2 = "CREATE TABLE " + Table2Name + "" +
"(line_id AUTOINCREMENT PRIMARY KEY ," +
"line_full_name CHAR(50) NOT NULL,"+
" network_id INTEGER FOREIGN KEY)";
有人可以告诉我这个问题的原因吗?如何解决?
【问题讨论】:
-
外键必须指向某处...
-
该查询很容易受到SQL Injection... ;(
-
@kape123:连接 SQL 字符串并不意味着它容易受到 SQL 注入攻击。这取决于
Table2Name变量的来源。而且由于这是CREATE TABLE语句中的表名,所以在这种情况下OP不能进行参数绑定。
标签: c# sql-server sql-server-2012