Connect Delphi to SQL database

Ouerghi Yassine picture Ouerghi Yassine · Nov 20, 2012 · Viewed 20.6k times · Source

I'm using Microsoft SQL Server R2 Express to create databases.

When I try to connect to a database using delphi, I have to use this Connection string :

ADOConnection1.ConnectionString := 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=db_formation;Data Source=EVILKID-pc\evilkid;';

where "EVILKID-PC\evilkid" is the name of my pc, enter image description here

As you can seem this will only work on my PC. What should I do to make it connect to localhost? I have tried changing the "Data Source" to "localhost" but it would not connect and I would get:

[DBNETLIN][ConnectionOpen(Connect()).]SQL Server does not exist or access denied

Any idea where the problem is?

Answer

Michael Fredrickson picture Michael Fredrickson · Nov 20, 2012

Even though your instance is on localhost, it's still a named instance that you'll need to specify in your connection string:

ADOConnection1.ConnectionString := '... Data Source=localhost\evilkid;';