SQL Server Can't drop database with hyphen-minus in its name

xa9qqrwz  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(109)

Can't drop a database with a hyphen-minus in its name. The database is called nfm_example-F2_6 .

The Delphi code looks like this:

try
 ...
finally
  DBConn.QueryExecNP('drop database [' + tempdbname + ']');
end;

The error message I get:

----------------------------------------------------------------------------------------------------
Exception data (stack trace(s) and additional data):
----------------------------------------------------------------------------------------------------
Root: EMSError: Incorrect syntax near '-'.
SQL error list
SQL error 1
  Incorrect syntax near '-'.
  Error code: 102
  OLEDB error code: -2147217900
  Severity: 15
  State: 1
  Procedure:
  Line number: 1
 
SQL query text: drop database [nfm_example-F2_6]
Call stack for exception thread

It's a Microsoft SQL Server 2017 - 14.0.2037.2

What's wrong?

More informatoin:

DBConn is connected to a different database either master or the productive database. Note variable name tempdbname .

The databasename is valid, since it's available and I can see it with SSMS.

As you can see in the exception, the SQL Server gets the query text as:

drop database [nfm_example-F2_6]

DBConn is an interface for TMSConnection from SDAC by devart.

toe95027

toe950271#

Please write to our support and describe your problem so that we can solve it quickly.

相关问题