Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Run DDL SQL Commands With Delphi

Posted on 2006-11-03
11
Medium Priority
?
442 Views
Last Modified: 2010-04-05
hello
i am working with delphi2005 and SQL server 2000
i want run sql commands (CREATE DATABASE,CREATE TABLE and attach,backup,restore ...) with delphi in run time.
please help me step by step with a example
thanks a lot
0
Comment
Question by:mr_mpz
  • 5
  • 3
  • 3
11 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 17869471
depending on your database and your privileges
you can place the ddl-statment in a query and use the execSQL-method

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 17869480
>delphi2005 and SQL server 2000
never used one of them

meikl ;-)
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 17872569
Use AdoCommand from Ado Components
or the SqlQuery from dbExpress
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:mr_mpz
ID: 17877446
dear frined
i am not a beginer in delphi,i am working with delphi from ver 2 until ver2005.
but i don't need work with sql server,i work with sql server 2000 now and i want backup from database in runtime in delphi or attach or disattach and more.
i test it woth ADO too,but all my request not work correct
with query this command not work correct,please help me with correct sample
thanks
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 17880211
No one said in comments that you are beginner ;-)

anyway, as me and meikl told you, any query component will work, also I prefer to use AdoCommand with ado for DLL statement, for example to create database just do

   cmd1.CommandText := 'create database SqlDB';
   cmd1.Execute;

and you can do any other DLL as the same way,

BTW, the adoCommand above attached to connection which connect to sql server without specifing a database

HTH
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 17880238
guess a typo

DLL -> DDL

meikl ;-)
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 17880303
Thanks Meikl :-)
0
 
LVL 1

Author Comment

by:mr_mpz
ID: 17881094
dear friends
thanks from you
i test this way (adocommand) for create database but this way doesn't work for other command.
please say to me a example for Attach database and deattach
thanks a lot
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 17888013
Hi,

It's also easy :-)

here's two buttons, one will deattach the database and the other to reattach it again

procedure TForm8.btnDeattachDBClick(Sender: TObject);
begin
  cmd1.CommandText :='sp_detach_db "pubs"';
  cmd1.Execute;
end;

procedure TForm8.btnAttachDBClick(Sender: TObject);
begin
  cmd1.CommandText :='sp_attach_single_file_db @dbname = "pubs", ' +
          ' @physname = "C:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf"';
  cmd1.Execute;
end;

Regards,
Mohammed
0
 
LVL 1

Author Comment

by:mr_mpz
ID: 17899981
dear mohammed
thanks from your answer,this work correct
in adocommand ,what is  connectionstring?
i want connect to sql server without ODBC
thanks
0
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 450 total points
ID: 17920627
for windows integerated security
Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=pubs;

if you use sql server security

Provider=SQLOLEDB.1;user id=sa;password=password;Initial Catalog=pubs;
0

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question