create database with parameters

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
RomanVD
Posts: 4
Joined: Sat 01 Jan 2011 17:43

create database with parameters

Post by RomanVD » Sat 01 Jan 2011 17:52

I use TMSSQL.
SQL-

CREATE DATABASE :MY_DB

Executing-

MSSQL1.ParamByName('MY_DB').Value:='test';
MSSQL1.Execute;

It doesn't work and error occures - Exception class EMSError with message 'Incorrect syntax near '@P1'.'.

But without parameter using, for example - CREATE DATABASE test
- everything is OK.

Why?
Last edited by RomanVD on Sun 02 Jan 2011 01:23, edited 1 time in total.

RomanVD
Posts: 4
Joined: Sat 01 Jan 2011 17:43

Post by RomanVD » Sun 02 Jan 2011 00:34

In SQL profiler I see:

declare @p3 varchar(8000)
set @p3='test'
exec sp_executesql N'CREATE DATABASE @P1;',N'@P1 varchar(8000) OUTPUT',@p3 output
select @p3

And when try it in studio I get:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '@P1'.

:?:

RomanVD
Posts: 4
Joined: Sat 01 Jan 2011 17:43

Post by RomanVD » Sun 02 Jan 2011 12:20

CREATE DATABASE does not support parameters.

That is the cause of my problem.

AndreyZ

Post by AndreyZ » Mon 03 Jan 2011 16:09

Hello,

SQL Server doesn't support parameters in the DDL instructions, only in DML.

Post Reply