[英]SQLDMO - [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '*'
I'm currently in charge of maintaining a legacy software. 我目前负责维护旧版软件。 Currently I'm having problem with SQLDMO as following:
目前,我在使用SQLDMO时遇到问题,如下所示:
//This function is used to create sql query for drop and create table
Function GenerateScript(ByVal pObjectType As String, ByVal pObjectName As String) As String
Dim sSQL As String = ""
If (pObjectType.ToLower() = "user") Then
If Not IsNothing(db.Users.Item(pObjectName)) Then
sSQL = db.Users.Item(pObjectName).Script(SQLDMO.SQLDMO_SCRIPT_TYPE.SQLDMOScript_Drops)
sSQL = sSQL + db.Users.Item(pObjectName).Script()
End If
Else
If Not IsNothing(db.GetObjectByName(pObjectName)) Then
sSQL = db.GetObjectByName(pObjectName).Script(SQLDMO.SQLDMO_SCRIPT_TYPE.SQLDMOScript_Drops)
sSQL = sSQL + db.GetObjectByName(pObjectName).Script() //Error occur here
End If
End If
Return sSQL
End Function
There are about 20 tables in my database, but only some of them reproduce the exception: 我的数据库中大约有20个表,但是只有其中一些会重现异常:
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '*'.
Please tell me what cause the problem and how to solve it 请告诉我造成问题的原因以及解决方法
Update I tried with 2 databases and find out that it run ok in one DB but produce the issue in the other. 更新我尝试使用2个数据库,发现它在一个数据库中可以正常运行,但在另一个数据库中会产生问题。 But those databases have the same table structure, so why do the error occur in one database and not occur in the other?
但是那些数据库具有相同的表结构,那么为什么错误在一个数据库中发生而在另一个数据库中没有发生?
Solve 解决
It was the compatible of the database that cause the problem. 导致问题的原因是数据库的兼容性。 It run ok with database that compatible with sql server 2005 (90) and produce error with database that compatible with sql server 2008 or above.
与兼容sql server 2005(90)的数据库可以正常运行,并且与sql server 2008或更高版本兼容的数据库会产生错误。 All I need to do is change to compatible of database to 2005
我要做的就是将数据库的兼容性更改为2005
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.