INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Does SQL Server work with dbExpress

Does SQL Server work with dbExpress

(OP)
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?

RE: Does SQL Server work with dbExpress

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...

RE: Does SQL Server work with dbExpress

(OP)
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();

RE: Does SQL Server work with dbExpress

(OP)
Is there some sort of edit button somewhere to edit a post?

RE: Does SQL Server work with dbExpress

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...

RE: Does SQL Server work with dbExpress

(OP)
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');

RE: Does SQL Server work with dbExpress

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...

RE: Does SQL Server work with dbExpress

(OP)
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

RE: Does SQL Server work with dbExpress

(OP)
I am trying to put it in the .dpr file (I would edit the above post but don't see how to do it).

RE: Does SQL Server work with dbExpress

(OP)
Here's something else that doesn't work:

function TestConnection:string;
begin
CoInitialize(nil); // undeclared identifier: 'CoInitialize'
try
Writeln('Debug Line 1');

RE: Does SQL Server work with dbExpress

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...

RE: Does SQL Server work with dbExpress

(OP)
Thanks. That did get me a little bit farther.

CODE --> Delphi

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!! 

RE: Does SQL Server work with dbExpress

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:

http://docwiki.embarcadero.com/RADStudio/XE6/en/Wo...

/Daddy

-----------------------------------------------------
Helping people is my job...

RE: Does SQL Server work with dbExpress

(OP)
Get the same exact error doing it that way. Yea, finding any useful relevant documentation on Delphi anymore is extremely difficult.

RE: Does SQL Server work with dbExpress

(OP)
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!

RE: Does SQL Server work with dbExpress

(OP)
Both of these work the same:

ADOConnection1.Connected := true;

ADOConnection1.Open();

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close