sql server - Why Does Delphi Console Application Need Form For TSQLConnection To Work? -


i have simple console application written using delphi xe2.

program project1;  {$apptype console}  {$r *.res}  uses   system.sysutils,   data.dbxmssql,   data.db,   data.sqlexpr;  var   myconnection: tsqlconnection;  begin   try     { todo -ouser -cconsole main : insert code here }      myconnection := tsqlconnection.create(nil);     myconnection.drivername := 'mssql';     myconnection.getdriverfunc := 'getsqldrivermssql';     myconnection.libraryname := 'dbxmss.dll';     myconnection.vendorlib := 'sqlncli10.dll';     myconnection.loginprompt := false;     myconnection.params.clear;     myconnection.params.add('drivername=mssql');     myconnection.params.add('schemaoverride=%.dbo');     myconnection.params.add('hostname=myserver');     myconnection.params.add('database=mydb');     myconnection.params.add('blobsize=1');     myconnection.params.add('localcode=0000');     myconnection.params.add('isolationlevel=readcommited');     myconnection.params.add('os authentication=true');     myconnection.params.add('prepare sql=false');     myconnection.connected := true;      writeln('myconnection connected');   except     on e: exception       writeln(e.classname, ': ', e.message);   end;    readln; end. 

when run this, error:

'dbx error: driver not initialized. client library may missing, not installed properly, of wrong version, or driver may missing system path.'

if add vcl form application, pop-up enabling "visual component library" framework, no to, , without doing else, when run application 'myconnection connected'.

the difference can see in uses clause:

uses   system.sysutils,   data.dbxmssql,   data.db,   data.sqlexpr,   unit1 in 'unit1.pas' {form1} 

if remove unit1 in 'unit1.pas' {form1} uses clause app fails connect.

i not want include form in console application, happening program when such works?

vcl internally calls coinitialize during initialization (initializes com library on current thread), console application doesn't (the same problem occurs in worker thread requiring com-stuff).
make coinitialize call in beginning of program or in initialization section, , couninitialize after work.

http://docwiki.embarcadero.com/radstudio/xe5/en/dbexpress_database_specific_information


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -