{"id":18284668,"url":"https://github.com/pplu/azure-sqlserver-sqldatawarehouse-perl","last_synced_at":"2026-04-12T02:32:07.495Z","repository":{"id":66753233,"uuid":"123148641","full_name":"pplu/azure-sqlserver-sqldatawarehouse-perl","owner":"pplu","description":"How to connect to Azure SQL Database and Azure SQL data warehouse","archived":false,"fork":false,"pushed_at":"2019-10-14T14:16:54.000Z","size":11,"stargazers_count":0,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-16T08:57:59.885Z","etag":null,"topics":["article","azure","azure-sql-database","dbi","debian","mssql","odbc","odbc-driver","perl","sql-data-warehouse","sql-server"],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pplu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-27T15:27:33.000Z","updated_at":"2019-10-14T14:16:56.000Z","dependencies_parsed_at":"2023-02-22T19:15:18.939Z","dependency_job_id":null,"html_url":"https://github.com/pplu/azure-sqlserver-sqldatawarehouse-perl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pplu/azure-sqlserver-sqldatawarehouse-perl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pplu%2Fazure-sqlserver-sqldatawarehouse-perl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pplu%2Fazure-sqlserver-sqldatawarehouse-perl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pplu%2Fazure-sqlserver-sqldatawarehouse-perl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pplu%2Fazure-sqlserver-sqldatawarehouse-perl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pplu","download_url":"https://codeload.github.com/pplu/azure-sqlserver-sqldatawarehouse-perl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pplu%2Fazure-sqlserver-sqldatawarehouse-perl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31702579,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T21:17:31.016Z","status":"online","status_checked_at":"2026-04-12T02:00:06.763Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["article","azure","azure-sql-database","dbi","debian","mssql","odbc","odbc-driver","perl","sql-data-warehouse","sql-server"],"created_at":"2024-11-05T13:14:19.529Z","updated_at":"2026-04-12T02:32:07.472Z","avatar_url":"https://github.com/pplu.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Using Azure SQL Database and Azure SQL DataWarehouse with Perl\n\nAzure SQL Database and Azure SQL DataWarehouse are two Azure services that are\nbased on SQL Server technology. The databases are hosted and managed by Azure, \nso, you don't have to worry about installing Microsofts' SQL Server on a VM.\n\nHosted database services are part of what makes Cloud attractive to me. In the\ntraditional infrastructure world, you have one big (and redundant) database server\nwhere everything goes. In the cloud, you can have one small database server for each\nproject, since things like PITR and backups are built-in. \n\nOne of Azure's most mature offerings is Azure SQL Database. Finding documentation\non how to consume some traditionally Windows-centric services for some environments\nis sometimes challenging, so this article will guide you for connecting to the \nAzure Database service from Perl.\n\nNote: this article is specific for the Azure hosted cloud services. If you're looking\nfor connecting to a traditional SQL Server, [this](https://github.com/pplu/perl-mssql-server)\nmay help.\n\n# Some background\n\nConnecting from a Linux environment to SQL Server is traditionally done via the ODBC (Open\nDatabase Connectivity) API. This API defines a common API for programming languages to bind\nto, letting the details of how to talk to the database be dealt with drivers. \n\nTraditionally, there was an Open Source project called FreeTDS which provided an ODBC interface, with nothing\nofficial from Microsoft. But times change and Microsoft released recently an ODBC driver for SQL\n\nServer for Linux and MacOS environments. So we'll go full speed in this article using the\nofficial MS ODBC driver.\n\n# Preparing the environment:\n\nThe base for the article is an Azure Debian 8 (Jessie) VM as provided by Azure. \n\nProvision a Debian 8 VM inside a new Resource Group. Also provision an SQL Database and an SQL data warehouse in\nthe same Resource Group (this is basically so we can clean up without hassle). \n\nOnce we have the two databases provisioned, we have to open their firewall rules to permit the IP of the\nVM we have created. Please take good note of the server name, the names of the dbs you've created,\nthe usernames and the passwords for the databases.\n\nNow log in to the Debian VM:\n\nWe'll use Perl's Carton bundler to install the latest versions of some dependencies (DBI, DBD::ODBC) in a local directory (so it doesn't mess up the system). Also we'll need git to download our sample script and build-essential because we'll be compiling some of the Perl modules\n\n```\nsudo apt-get install -y carton git build-essential\n```\n\nWe'll need the UNIX ODBC library, and its' dev package (to compile the DBD::ODBC module).\n```\nsudo apt-get install -y unixodbc unixodbc-dev\n```\n\nNow we'll need to install the Microsoft ODBC driver. [Debian packages](https://docs.microsoft.com/es-es/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server)\n\n```\nsudo su -\napt-get install -y apt-transport-https curl\ncurl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -\ncurl https://packages.microsoft.com/config/debian/8/prod.list \u003e /etc/apt/sources.list.d/mssql-release.list\napt-get update\nACCEPT_EULA=Y apt-get install msodbcsql\nexit\n```\n\nNow we'll download the example script from this repo:\n```\ngit clone https://github.com/pplu/azure-sqlserver-sqldatawarehouse-perl.git\ncd azure-sqlserver-sqldatawarehouse-perl\n```\nNow install the local dependencies with carton (they are in the cpanfile of the repository).\n```\ncarton install\n```\n\n# Connecting to the Azure SQL\n\n```\ncarton exec ./connect.pl server_name db_name username password\n```\nWill create a table and insert some rows in it. It will work if you point the script to either \nan Azure SQL Database or an Azure SQL data warehouse.\n\nYou're done! Happy Hacking.\n\nRemember to delete the Resource Group for all your stuff to be cleaned up ;)\n\n# Additional notes\n\n## Named DSN\n\nIn the example, the DSN for ODBC is inlined in the connect call to DBI. You can connect via a named DSN also.\n\n```\nmy $dbh = DBI-\u003econnect(\"dbi:ODBC:testdsn\", $user, $password, { RaiseError =\u003e 1 });\n```\n\nWith the `odbcinst -q -s` command you can see what DSNs are configured in your system. In the example we're using `testdsn`\n\nIn /etc/odbc.ini you should have:\n\n```\n[ODBC Data Sources]\ndata_source_name = testdsn\n\n[testdsn]\nDriver = /opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.9.1\nDESCRIPTION = Microsoft ODBC Driver 13 for SQL Server\nSERVER=localhost,1401\n```\n\n## libiodbc2 incompatibility\n \nIt looks like the DBD::ODBC has problems if you have libiodbc2 installed.\nIf you don't want to uninstall libodbc2, just take a look at \n[this stack overflow question](https://stackoverflow.com/questions/11354288/undefined-symbol-sqlallochandle-using-perl-on-ubuntu) for how to avoid the problem without removing libodbc2\n\n```\nsudo apt-get remove --purge libiodbc2\n```\n\n## Why didn't you use Debian 9 (stretch)?\n\nI didn't use Debian 9 (stretch) because the msodbcsql package isn't there (although it's\nannounced to be released). This seems like a transitive problem with the Microsoft Debian \nrepos, but I've prefered to document a working solution. \n\nYou should be able to do the same steps on Debian 9 (with the precaution of changing the 8 for a 9 when configuring the Debian repos).\nIf you don't, the following error will happen.\n\n\n## Can't open lib libmsodbcsql: file not found (SQL-01000) error\n\nI was getting this error when connecting:\n\n```\nuser@DebianHost:~/azure-sqlserver-sqldatawarehouse-perl$ carton exec perl connect.pl\nDBI connect('Driver=ODBC Driver 13 for SQL Server;Server=xxx.database.windows.net','user',...)\nfailed: [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.9.2' : file not found (SQL-01000) at connect.pl line 16.\n```\n\nStrangely, the file reported as not found was on the filesystem (ls would report it without problems).\nI finally found out what was happening: `/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.9.2` is \ndynamically linked against other libraries.\n\n```\nldd /opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.9.2 | grep \"not found\"\n```\n\ngave away the problem. The \"not found\" was due to other .so's missing (not the \nlibmsodbcsql-13.1.so.9.2 itself). The problem was that I had installed the ODBC driver \nfrom the the Debian 8 repositories on Debian 9 because I had mis-copied the Debian \napt repo paths (ups!). I'm documenting this because I suspect this can happen to anyone, \nhoping that Google will index it high enough for it to be found easily.\n\n# Can you get the Debian 8 msodbcsql package to work on Debian 9?\n\nYou can install the Debian 8 msodbcsql package on Debian 9 just using the Microsoft repositiores\nfor Debian 8, but as you know from the last paragraph, it's broken.\nYou can rest your system into submission by installing the libssl package that belongs to Debian 8\n(which has the appropiate missing libraries).\n\n```\nwget http://ftp.de.debian.org/debian/pool/main/o/openssl/libssl1.0.0_1.0.2l-1~bpo8+1_amd64.deb\nsudo dpkg -i libssl1.0.0_1.0.2l-1~bpo8+1_amd64.deb\n```\n\nI really don't know what sort of pain is in for you if you do this. The example script works,\nbut there may be dragons down the road. You've been warned.\n\n# Additional links that helped me get this running:\n\nhttps://github.com/pplu/perl-mssql-server\n\nhttps://stackoverflow.com/questions/4905624/how-do-i-connect-with-perl-to-sql-server\n\nhttps://metacpan.org/pod/DBD::ODBC\n\nhttps://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker\n\nhttps://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-docker\n\nhttps://www.connectionstrings.com/sql-server/\n\n# Author, Copyright and License\n\nThis article was authored by Jose Luis Martinez Torres.\n\nThis article is (c) 2018 CAPSiDE, Licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).\n\nThe canonical, up-to-date source is [GitHub](https://github.com/pplu/azure-sqlserver-sqldatawarehouse-perl). Feel free to contribute back.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpplu%2Fazure-sqlserver-sqldatawarehouse-perl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpplu%2Fazure-sqlserver-sqldatawarehouse-perl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpplu%2Fazure-sqlserver-sqldatawarehouse-perl/lists"}