Forum > Databases
TMSSQLConnection + SQL Server 2016 (v13)
Sniper:
Anyone did the connection to latest SQL database?
I could not do it with FreeTDS(dblib.dll) on Win64 with Lazarus 32-bit. Is it possible?
Thaddy:
Afaik, FreeTDS hasn't been updated (stable) since 2015, so unless you build it yourself from git https://github.com/FreeTDS/freetds.....
Alternatively you can use ODBC.
hmprof:
Personally I use
Lazarus 1.8.0 r56594 FPC 3.0.4 i386-win32-win32/win64
+ SQL Server 2014
+ TMSSQLConnection
It's working really well.
Proceed as follows:
1 - You have to download the dll from the link below :
ftp://ftp.freepascal.org/fpc/contrib/windows/dblib_1.00.zip
2 - Decompress the file dblib_1.00.zip
3 - Retrieve the 2 dll files, below, from the subdirectory
..\dblib_1.00.zip\Win32\
dblib_2008.dll
libiconv2.dll
4 - Copy the 2 dll files (dblib_2008.dll and libiconv2.dll) in the same directory of your executable program
5 - and finally, Rename the dblib_2008.dll file to dblib.dll (this last point, not very intuitive, is important !)
A+
hmprof:
Below is a simple example for connecting to a SQL Server instance and opening a query in a DBGrid
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.BtnConnexionExample01Click(Sender: TObject);begin with MSSQLConnectionExample01 do begin if Connected then Connected := False; HostName := 'MACHINE01\INSTANCE01'; // The name of your instance SQL Server DatabaseName := 'master'; UserName := 'sa'; // Authentication SQL Server : User name Password := '*********'; // Authentication SQL Server : Password // CharSet :// - if you use Microsoft DB-Lib and set to 'UTF-8' then char/varchar fields will be UTF8Encoded/Decoded// - if you use FreeTDS DB-Lib then you must compile with iconv support (requires libiconv2.dll)// or cast char/varchar to nchar/nvarchar in SELECTs CharSet := 'UTF-8';// Params :// "AutoCommit=true" - if you don't want explicitly commit/rollback transactions// "TextSize=16777216" - set maximum size of text/image data returned// "ApplicationName=YourAppName" - Set the app name for the connection. Params.Clear; Params.Add('AutoCommit=true'); Params.Add('TextSize=16777216'); Params.Add('ApplicationName=YourAppName'); // Connected := True; // See below end; with SQLTransactionExample01 do begin if Active then Active := False; DataBase := MSSQLConnectionExample01; end; { use Database NameOfMyDatabase (other than master) } MSSQLConnectionExample01.DatabaseName := 'NameOfMyDatabase'; with SQLQueryExample01 do begin if Active then Close; DataBase := MSSQLConnectionExample01; Transaction := SQLTransactionExample01; SQL.Clear; SQL.Add('SELECT Id, Column1, Column2, Column3... '); SQL.Add('FROM dbo.NameOfMyTable '); SQL.Add('WHERE Id = 100'); // Open; // See below end; DataSourceExample01.DataSet := SQLQueryExample01; DBGridExample01.DataSource := DataSourceExample01; { Connection } with MSSQLConnectionExample01 do begin if Connected then Connected := False; Connected := True; end; { Open SQLTransaction } with SQLTransactionExample01 do begin if Active then Active := False; Active := True; end; { Open query } with SQLQueryExample01 do begin if Active then Close; Open; end;end;
A+
Thaddy:
@hmprof
The question is about mssqlserver 2016, not mssqlserver 2008..... Yes, that works, but 2016 does not!
This is a valid question. Alas, the third-party software has no stable release for it, since it is from 2015.
You need to build it from source to get it working.
See the link I gave. Note the ODBC path I suggested will also work, but is partly limiting functionality.
Navigation
[0] Message Index
[#] Next page