Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does SQL Server work with dbExpress

Status
Not open for further replies.

cupboy2013

Programmer
Mar 21, 2013
27
US
I have the professional version of XE5. How might I connect to a SQL Server database or does that require additional software purchases?

Also I could not try the example because it says DBXMsSQL.dcu file not found. Where might I find this file or does that cost extra?
 
Just use the plain TADOxxx components, they work on all delphi versions (and you don't need the extra DBEXpress libraries).
All you need is SQL server native client installation on the client PC's.

/Daddy

-----------------------------------------------------
Helping people is my job...
 
I've been working with this in a unit. Can't figure out how to call the Create method. It doesn't like the word self. I also tried nil. What might I use then?

code:
ADOConnection1 := Data.Win.ADODB.TADOConnection.Create(Self); // undeclared identifier Self
ADOConnection1.ConnectionString := 'Provider=MSDASQL.1;Data Source=localhost;Initial Catalog=rec1;Integrated Security=True';
//ADOConnection1.Open();

 
Is there some sort of edit button somewhere to edit a post?
 
nope, not on this site :)

You can create the connection passing nil as owner.
Don't forget to cleanup though (ADOConnection1.Free) if you no longer need the connection.

/Daddy

-----------------------------------------------------
Helping people is my job...
 
I already tried nil. That doesn't work either. It results in this error: EOleSysError: GoInitialize has not been called

Writeln('Debug Line 1');
ADOConnection1 := Data.Win.ADODB.TADOConnection.Create(nil); // EOleSysError: GoInitialize has not been called.

Writeln('Debug Line 2');
ADOConnection1.ConnectionString := 'Data Source=localhost;Initial Catalog=rec1;Integrated Security=True';
Writeln('Debug Line 3');
 
ah, that makes sense!.

you are using a console application I presume?

Then you must initialize COM yourself (a VCL forms application does this out of the box).

just add this to your main unit:

Code:
uses
  ActiveX, ...

implementation

...


initialization
 CoInitialize(nil)
finalization
 CoUninitialize;

/Daddy

-----------------------------------------------------
Helping people is my job...
 
Well, with this program anything that can go wrong will go wrong. Although I've used the Initialization section in the past, and have samples, even if I do it the same way I get this error:

expected END but received INITIALIZATION
 
I am trying to put it in the .dpr file (I would edit the above post but don't see how to do it).
 
Here's something else that doesn't work:

function TestConnection:string;
begin
CoInitialize(nil); // undeclared identifier: 'CoInitialize'
try
Writeln('Debug Line 1');
 
you must use ActiveX unit!

Code:
unit test;

interface

uses
  ActiveX, ...

implementation

...

procedure Testing;
begin
 // use ADO objects
end;

initialization
 CoInitialize(nil)
finalization
 CoUninitialize; 
end.

-----------------------------------------------------
Helping people is my job...
 
Thanks. That did get me a little bit farther.
Code:
function TestConnection:string;
  begin
    try
      Writeln('Debug Line 1');
      ADOConnection1 := Data.Win.ADODB.TADOConnection.Create(nil);  

      Writeln('Debug Line 2');
      ADOConnection1.ConnectionString := 'Data Source=localhost;Initial Catalog=rec1;Integrated Security=True';
      Writeln('Debug Line 3');
      ADOConnection1.Open();
      Writeln('Debug Line 4');
      System.SysUtils.Sleep(1000);
      ADOConnection1.Close;
      Writeln('Debug Line 5');
      result:='Connection successful!';
    except
      on E: Exception do
        begin
          Writeln(E.ClassName, ': ', E.Message);
          result:='Connection failed!!';
        end
    end;



output:
Debug Line 1
Debug Line 2
Debug Line 3
EOleException: Multiple-step OLE DB operation generated errors. Check each OLE D
B status value, if available. No work was done
Result: Connection failed!!
 
Don't use Open, just set Connected to True.

It seems that you have zero experience with ADO/DB components, please do find online examples and consult at least the manual:


/Daddy

-----------------------------------------------------
Helping people is my job...
 
Get the same exact error doing it that way. Yea, finding any useful relevant documentation on Delphi anymore is extremely difficult.
 
The connection string was bad.

The correct one:
ADOConnection1.ConnectionString := 'Provider=SQLNCLI10.1;Integrated Security=SSPI;Persist Security Info=False;User ID="";Initial Catalog=rec1;Data Source=localhost;Initial File Name="";Server SPN=localhost';

And it works!
 
Both of these work the same:

ADOConnection1.Connected := true;

ADOConnection1.Open();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top