Creating a database in Firebird using FireDac (Delphi)

假装没事ソ 提交于 2019-12-23 14:55:24

问题


I recently changed from AnyDac to FireDac (8.0.5.3365). We're running Delphi 2006.

When I was using the AnyDac version of this component I could create a new database by doing the following..

Setup my connection

fConnection.LoginPrompt := false;
fConnection.ResourceOptions.SilentMode := true;

fConnection.Params.Clear;
fConnection.Params.Add(Format('DriverID=%s',          ['IB']));
fConnection.Params.Add(Format('Database=%s',          [fConnectionInfo.xDatabase]));
fConnection.Params.Add(Format('CharacterSet=%s',      ['UTF8']));
fConnection.Params.Add(Format('user_name=%s',         [fConnectionInfo.xUserName]));
fConnection.Params.Add(Format('password=%s',          [fConnectionInfo.xPassword]));
fConnection.Params.Add(Format('ExtendedMetadata=%s',  ['True']));
fConnection.Params.Add(Format('CreateDatabase=%s',    ['Yes']));
fConnection.Params.Add(Format('Protocol=%s',          ['Local']))

//database path = C:\Users\LoginName\AppData\Local\AppName\TestDB.FDB

Open and close the connection

fConnection.Open;
fConnection.Close;

And then I could run my create table sql scripts on the existing database.

But now when I do this with the FireDac version, the Open command raises the fbe_unavailable error as if I didn't specify the CreateDatabase parameter.

Should I be doing this a different way?

Thanks for your time.

Corey.


回答1:


You have a full example here http://docwiki.embarcadero.com/RADStudio/Rio/en/Executing_SQL_Scripts_%28FireDAC%29

For example, the following Firebird script creates a database, and can be executed using TFDScript:

SET SQL DIALECT 3;
SET NAMES UTF8;
SET CLIENTLIB 'C:\fb25\bin\fbclient.dll';
CREATE DATABASE 'E:\Test2.ib'
  USER 'sysdba' PASSWORD 'masterkey'
  PAGE_SIZE 16384
  DEFAULT CHARACTER SET NONE;

SET TERM ^ ;

CREATE PROCEDURE MY_PROC RETURNS (aParam INTEGER) AS
BEGIN
  aParam = 10;
END^

You should use CreateDatabase=Yes connection definition parameter additionally to other required parameters: http://docwiki.embarcadero.com/RADStudio/Rio/en/Connect_to_Firebird_(FireDAC)



来源:https://stackoverflow.com/questions/21312811/creating-a-database-in-firebird-using-firedac-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!