I'm using Delphi XE4 & SQL server express 12, locally on C drive. I can link Delphi to Access DB via ADO comp. Problem is when I try linking SQL server db - it doesn't see my server/db. I'm not sure how I should specify my server name (USER-PC\SQLEXPRESS - name created by SQLserver) or my db name (C:\Program Files(x86)\Microsoft SQL Server\MSSQL11.SQLExpress\MSSQL\DATA\TestDB.Mdf). No passwords used. I tried via ADoTable (SQL SERVER Native Client 11.0 as well as Microsoft OLE DB Provider for SQL Server) and TSQLConnection. (I've been using MS Access lately - out of touch with external db connection...)
-
Which edition of Delphi? Only the higher editions support client/server DBs.David Heffernan– David Heffernan2013-05-14 11:52:53 +00:00Commented May 14, 2013 at 11:52
-
1That's the version, which is clearly stated in your question. But I want to know which edition you are using?David Heffernan– David Heffernan2013-05-14 12:02:08 +00:00Commented May 14, 2013 at 12:02
-
a valid connectionstring would be : Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=YOURDB;Data Source=YOURSERVER\YourInstance;bummi– bummi2013-05-14 12:03:17 +00:00Commented May 14, 2013 at 12:03
-
Also, for future reference, using tags that are completely unrelated to the question is very bad form. That just confuses people interested in those tags.David Heffernan– David Heffernan2013-05-14 12:03:22 +00:00Commented May 14, 2013 at 12:03
-
Ok, I'm new to this, am not exactly sure what I did wrong @David? Embarcadero® Delphi® XE4 Version 18.0.4854.59655. Not sure where to look for edition?user2378627– user23786272013-05-14 12:08:35 +00:00Commented May 14, 2013 at 12:08
3 Answers
You need to provide the server information somehow, you can use a ConnectionString which is then used to build the connection. The connection string looks like this:
ConnString =
'Provider=SQLOLEDB.1;Persist Security Info=False;' +
'User ID=%s;Password=%s;Data Source=%s;Use Procedure for Prepare=1;' +
'Auto Translate=True;Packet Size=4096;Use Encryption for Data=False;'+
'Tag with column collation when possible=False';
Take a look at this example uing ADOQuery.
And take a look at the documentation: Connecting to Databases - Overview
2 Comments
If you right-click on the TADOConnection component, you will have an option to Edit Connection String. This opens a dialog, with a button labelled Build...
Clicking this opens a wizard. Select "Microsoft OLE DB Provider for SQL Server" as the provider, and click Next. You are now offered a list of all the SQL Servers that are currently visible. If yours is not in this list then it is unavailable. Has the SQL Server service been started?
If it is in the list then follow the wizard through to build a valid connection string.
3 Comments
Actually, you have to get connected to MSSQL Express with no regard to bitness (32/64). Your SQL Server Express have enabled the TCP/IP and/or Named Pipes connectivity instead of just Shared Memory?
To check, launch SQL Server Configuration Manager (don't know if it changed on 2012, but it's the name on 2008/2008r2) and look under SQL Server Network Configuration/Protocols for < your server instance > item (it'll have 2 of these on 64 bit systems, if my memory not failed me - my machine is 32bit, check on both).