# Win32::SqlServer 2.016

This is Win32::SqlServer, a module for calling Microsoft SQL Server from Perl through OLE DB.

Copyright © 2004-2026 Erland Sommarskog. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

### Brief Overview

Win32::SqlServer is a module that permits you to access SQL Server from Perl, by using any of Microsoft's OLE DB providers for SQL Server. Win32::SqlServer exposes two levels of interface, a high-level interface and a mid-level interface. The mid-level interface exposes a few more knobs at the price of somewhat more verbose code. A special feature of Win32::SqlServer is that you get fine-grained control for error handling.

There is no support for DBI. This module does not run on Unix – or any other non-Windows OS for that matter.

### Prerequisites

- Perl 5.32 or later.
- Windows 7 SP1 or later (Client O/S), Windows Server 2008 R2 SP1 or later (Server O/S). For versions before Windows 10, you need to have the update in KB2999226 installed.
- SQL Server 2000 or later, or any of Azure SQL Managed Instance, Azure SQL Database and Fabric SQL Database. The testing against the latter two is limited, though.
- An OLE DB provider for SQL Server. SQLOLEDB comes with the OS, but it is very outdated. I recommend downloading and installing Microsoft OLE DB Driver 19 for SQL Server.

For details, see the Prerequisites section in the Win32::SqlServer manual.

### Support for Older Platforms

If you need support for older platforms than listed above, you can use an older version of Win32::SqlServer as follows:

- For support for Perl 5.24, 5.26, 5.28 and 5.30, use version 2.014 of Win32::SqlServer.
- For support for Perl 5.20 and Perl 5.22, use version 2.012 of Win32::SqlServer.
- For support for Perl 5.18, use version 2.011 of Win32::SqlServer.
- To able to connect to SQL 7, use version 2.011 of Win32::SqlServer.
- For support for Perl 5.12, 5.14 or 5.16, use version 2.010 of Win32::SqlServer.
- For support for older operating systems (Windows XP, Windows 2003, Windows 2000), use version 2.010 of Win32::SqlServer.
- For support for Perl 5.8 or 5.10, you can use version 2.008 of Win32::SqlServer.
- To connect to SQL Server 6.5, use version 2.008 of Win32::SqlServer.

### What's in This Kit

The zip file includes x86 and AMD64 binaries for Perl 5.32, 5.34, 5.36, 5.38, 5.40 and 5.32. The binaries have been successfully tested with the corresponding versions of Strawberry Perl where available at the time of the release. (32-bit version for 5.32, and the 64-bit version for Perl 5.32, 5.34, 5.36, 5.38, 5.40 and 5.42.) Strawberry Perl has also produced a 32-bit Perl for 5.38, however some of my test scripts misbehaved, for reasons I have not been able to figure out.

I have not tested this version of Win32::SqlServer against ActivePerl (too much hassle), but from experience in the past, I expect it to work. (However, it is possible that ActivePerl have used different compilation settings from StrawberryPerl for later Perl versions, and in such case you will get a handshake error.)

Note that the 32-binaries in the kit for 32-bit Perl are built with the option USE_64_BIT_INT set. They will not run with a 32-bit Perl built without this option.

The kit also includes source code and test scripts. For information how to build from sources, see below.

The binaries were built on Windows 11 with the Visual Studio 2022 C++ compiler, using Perl installations that I built myself from the Perl source in the same manner.

How to Install the binary

- Extract the zip file anywhere you like.
- Open a Command Prompt, and change directory to where you extracted the files.
- Run the script Win32-SqlServer-install.pl. This script inspects your PATH to determine where your Perl installation is, and installs the files according to the structure used by Perl.
- You can prevent the script from searching by giving the top directory for your Perl installation yourself. E.g.:

          perl Win32-SqlServer-install.pl C:\Perl

To test that the installation is OK, either run any of the test scripts that comes with Win32::SqlServer and which are detailed in tests.html, or run any of the sample scripts in the manual.

### Manual

The manual is in Win32-SqlServer.html. activeperl-copy.pl also installs it as html/site/lib/Win32/SqlServer.html There is a POD file as well, but there is no real contents in it, only a pointer to the HTML file.

### Reporting Bugs or Problems

Please mail bug reports and suggestions to esquel@sommarskog.se. Try to make your reports as specific as possible. Particularly do not forget to include which versions of Perl, Windows, SQL Server etc you are using.

I usually try to respond within 24-48 hours, but if I am on holiday I am.

## Building from Sources

### Prerequisites

To build Win32::SqlServer you need:

- The Platform SDK for Windows, more precisely, the Core SDK and the MDAC SDK. The Platform SDK comes with Visual Studio.
- The SDK (header files and link libraries) for Microsoft OLE DB Driver 19 for SQL Server.
- Perl 5.12 or later. (But note that I don't support Perl 5.32 and earlier.)
- A C++ compiler, preferably Visual C++ 14.0 or later. I have only tested with the C++ compiler from Visual Studio 2022.
- A make facility.

If you want to build Win32::SqlServer with another compiler than Visual C++, you are welcome to try. I am certainly interested to know if you succeed, but I am afraid that I cannot give any help in the matter – it's way beyond my realm. (I'm an SQL Server guy, after all.)

Note that the Perl environment you build in, should have been configured with the same compiler as you are using. That is, you cannot build Win32::SqlServer using Visual Studio with Strawberry Perl or ActivePerl, as they are configured with gcc.

### How to Build and Install

Text in `this type face` indicates command you run from the command prompt.

1. Extract the zip file anywhere you like.
2. Edit makefile.pl so that `$SQLDIR` points to where the SDK for Microsoft OLE DB Driver 19 for SQL Server is located.
3. If you use a different compiler from Visual C++, you need to review makefile.pl more closely as makefile.pl may include options that are specific to Visual C++.
4. Note that makefile.pl explicitly lists which libraries to link with, and specifies the MT flag for the C compiler. This is to force use of the static C run-time library for Visual C++, which is what I want for the binary distribution. Change this if you like.
5. Open a Command Prompt, and change directory to where you extracted the files.
6. `Perl makefile.pl`.
7. `MAKE`
   Or `NMAKE`, `DMAKE` or whatever your MAKE utility you use.
8. `MAKE test`
   Before you run the tests, please read tests.html so that you understand what impact the test scripts have on your server. This document also describes how to set the environment variable OLLEDBTEST, from which the test scripts get information how to log into SQL Server.
9. `MAKE install`

Last updated 26-01-05 23:29