This is Win32::SqlServer, a module for calling Microsoft SQL Server from Perl
through OLE DB.
Copyright © 2004-2018 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.
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.
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.
- Perl 5.18 or later.
- Windows 7 SP1 or later (Client O/S), Windows Server 2008 R2 SP1 or later (Server O/S). Depending on which compiler you use to build the module, you may need to install the update in KB2999226 if you are on versions before Windows 10.
- SQL Server 7 or later. Note that Windows Azure SQL Database has not been tested.
- 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 for SQL Server, originally released in March 2018.
For details, see the Prerequisites section in the Win32::SqlServer manual.
Prerequisites for building, see below under Building from
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.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
This is the source-only distribution for CPAN,
and do not include any binaries for Win32::SqlServer. If you want a binary distribution
(for x86 or AMD64) please visit
The manual is in 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
firstname.lastname@example.org. 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.
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. You can
also download the
Windows SDK for Windows Server 2008 and .NET Framework 3.5.
(The link is the current as of this writing. Microsoft often twitches things
around, so you have to search for it.)
- The SDK (header files and link libraries) for Microsoft OLE DB Driver for SQL Server. Note that the SDK files are not installed by default when you install the provider.
- Perl 5.18 or later.
- A C++ compiler, preferably Visual C++ 14.0 or later. If you don't have
Visual Studio, the Windows SDK (see above), comes with one. I have only tested with the C++ compiler from Visual Studio 2017.
- A make facility. Microsoft's NMAKE also
comes with the Windows SDK.
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 with Strawberry Perl, or ActivePerl 5.18 or later, as they are configured with gcc.
How to Build and Install
Text in this type face indicates command you run from the command
- Extract the zip file anywhere you like.
- Edit makefile.pl so that
$SQLDIR points to where the SDK for Microsoft OLE DB Driver for SQL Server is located.
- 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++.
- 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.
- Open a Command Prompt, and change directory to where you extracted the
- Perl makefile.pl.
Or NMAKE, DMAKE or whatever your
MAKE utility you use.
- 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.
- MAKE install
Last updated 18-04-17 21:31