Board index » delphi » How to pass Database Name Parameter to SQL Server Procedure from ADOCommand

How to pass Database Name Parameter to SQL Server Procedure from ADOCommand

I am trying to call from Delphi 6.0 ADOCommand the following but I get an
error in the first parameter of the Database Name. In the parameters, the
mDatabaseName, mNewPassword and mLogIn are ftString types.

use [:mDatabaseName]
EXEC sp_password NULL, :mNewPassword, :mLogIn

If I hard code the below in the ADOCommand it works ok.

use [ConyersDatabase]
EXEC sp_password NULL, 'moon', 'John'

How would I be able to pass the mDatabaseName parameter correctly? the
mNewPassword and mLogIn are being passed correctly but not the
mDatabaseName.

Thanks

--

Peace in Christ,
Marco Napoli
http://www.ourlovingmother.org
http://www.avantitec.com

 

Re:How to pass Database Name Parameter to SQL Server Procedure from ADOCommand


I suspect the problem is that ADO puts single quotes around the database
name because it believes it is a string parameter.
As a result, this is what is sent to server:
use ['ConyersDatabase']
which will not work.

I have no idea how to tell ADO not to use apostrothes, but I would do this
stuff in another way: just assign ADOCommand.CommandText dynamically before
you open it.

ADOCommand.CommandText := 'use ' + MyDatabaseName;

Quote
"Marco Napoli" <ma...@avantitec.com> wrote in message

news:3e8e1087$1@newsgroups.borland.com...
Quote
> I am trying to call from Delphi 6.0 ADOCommand the following but I get an
> error in the first parameter of the Database Name. In the parameters, the
> mDatabaseName, mNewPassword and mLogIn are ftString types.

> use [:mDatabaseName]
> EXEC sp_password NULL, :mNewPassword, :mLogIn

> If I hard code the below in the ADOCommand it works ok.

> use [ConyersDatabase]
> EXEC sp_password NULL, 'moon', 'John'

> How would I be able to pass the mDatabaseName parameter correctly? the
> mNewPassword and mLogIn are being passed correctly but not the
> mDatabaseName.

> Thanks

> --

> Peace in Christ,
> Marco Napoli
> http://www.ourlovingmother.org
> http://www.avantitec.com

Re:How to pass Database Name Parameter to SQL Server Procedure from ADOCommand


Ok. Thanks. I was afraid of that. I lots of other lines of code with similar
parameters to pass. I was hoping there was another way.

Marco

Quote
"Alexander Bach" <al...@softhome.net> wrote in message

news:3e91544c@newsgroups.borland.com...
Quote
> I suspect the problem is that ADO puts single quotes around the database
> name because it believes it is a string parameter.
> As a result, this is what is sent to server:
> use ['ConyersDatabase']
> which will not work.

> I have no idea how to tell ADO not to use apostrothes, but I would do this
> stuff in another way: just assign ADOCommand.CommandText dynamically
before
> you open it.

> ADOCommand.CommandText := 'use ' + MyDatabaseName;

> "Marco Napoli" <ma...@avantitec.com> wrote in message
> news:3e8e1087$1@newsgroups.borland.com...
> > I am trying to call from Delphi 6.0 ADOCommand the following but I get
an
> > error in the first parameter of the Database Name. In the parameters,
the
> > mDatabaseName, mNewPassword and mLogIn are ftString types.

> > use [:mDatabaseName]
> > EXEC sp_password NULL, :mNewPassword, :mLogIn

> > If I hard code the below in the ADOCommand it works ok.

> > use [ConyersDatabase]
> > EXEC sp_password NULL, 'moon', 'John'

> > How would I be able to pass the mDatabaseName parameter correctly? the
> > mNewPassword and mLogIn are being passed correctly but not the
> > mDatabaseName.

> > Thanks

> > --

> > Peace in Christ,
> > Marco Napoli
> > http://www.ourlovingmother.org
> > http://www.avantitec.com

Other Threads