My *nix world

MS-SQL Server on Linux? Yes, it works!

I've read hundreds of posts/articles that simply claim that MS-SQL Server does not work on Linux. Let me tell you this: that's hogwash!

I have successfully installed MSDE 2000 (32-bit) on a Linux i686 architecture, more specifically on a Gentoo 32-bit machine where I have the WineHQ API framework, which allows applications designed for MS Windows to run on a POSIX-compliant OS.

Contents

  1. Prerequisite
  2. Configuration
  3. Setup
  4. Tests
  5. Troubleshooting
  6. Later MS-SQL versions (eg. MS-SQL 2005,2008,etc)

Prerequisite

Configuration

  • run winescript
    • click on "Select the default wineprefix" then OK
    • click on "Run winecfg" then OK
    • on Windows Version drop-down select Windows XP (or later version; I have tested Windows XP so at least I know that it works); Apply+OK
  • Install a Windows DLL or component
    • check dotnet20 (I'm not really sure that it is absolutely necessary), mdac27/mdac28 then press OK; after installing these packages close the winetricks application

Setup

  • run the following commands:
    • it's possible that the setup crashes; don't worry, run the following command:

The above statement copies the remaining setup' DLL into windowssystem32 folder. After the setup.exe returns (with whatever output messages you may find on your terminal) it would be a good idea to wait few minutes (because it's a chance that it still copies/starting/doing something while you think you are done). Then, just run the following command:


to make sure that there is a sqlservr.exe process running out there (it may appear as , but don't worry about that).

Normally the MSSQLSERVER service should be started automatically (by setup, right after the installation finishes). You can check this in at least three ways:

  • in your terminal run the command "wine net start MSSQLSERVER"; it should return an output like this:
  • in your terminal run the command "ps aux|grep -i sqlservr.exe"; if MSSQLSERVER is running then the command above should show the corresponding process
  • in your terminal run the command

it will start an M$ application that allows you to control the MSSQLSERVER services.

If it seems that it's not installed properly then it is worthing reading also this post.

Tests

To check the stability and performance of MS-SQL SERVER 2000 Desktop Engine (MSDE) under Linux, I've done few tests.

Test 1: migrate a SQL2008 database (from a Windows Server) to the SQL 2000 (MSDE) instance that runs on top of Linux:

  • I have a SQL2008 database (1GB data) with the following objects:
    • tables: 1043
      • primary keys: 1002
      • indexes: 95
      • defaults: 19569
      • triggers: 3819
    • views: 361
    • stored procedures: 1314
    • functions: 866

I exported this database from SQL 2008 to SQL 2000 (MSDE) instance. It exported successfully!

I created the script for all triggers, stored procedures, functions then I run the script against the SQL 2000 (MSDE) instance on Linux. It ran successfully!

The database is (in fact) the server component of a client-server ERP package.

I have also a client application (the client component of the mentioned ERP package) that was built to run on Windows but thanks to WineHQ it runs also on Linux.

I have also installed the MDAC 2.8 on this Linux machine so that the client application connects the server component (the SQL database) by using the ADO components.

I have run the client application against the new SQL Server under Linux, so the entire solution (designed for Microsoft Windows) runs now on top of Linux. It works just perfectly!

Note: I haven't found a way to determine SQL Server to use as many CPU as Linux provides. Maybe it's something between SQL Server and WineHQ, I don't know. So for the time being my SQL Sever seems to use only 1 CPU:

ms sql server does work on linux

Screen capture of sqlservr.exe process

Also I've found out that the process name will appear as "sqlservr.exe ". A defunct process means that it's finished but still depends on its parent which is still alive. Well, I don't know about that, SQL Server looks pretty alive to me :o)

I hope that I've convinced you so far that in fact MS SQL Server does work on Linux.

Troubleshooting

  1. If the SQLServer server connection doesn't work

I have found out that sqlservr.exe (that seems for a reason) will not respond if you don't have a live connection to it that keeps him alive.

For instance, you may run the "SQL Server Service Manager" tool by running the following command:


ms sql server does work on linux

SQL Server Service Manager

By using this application you can start/stop the SQL Server service.

Also I found out that we can use the osql tool to stay connected on the SQL Server and to keep it alive:

This will give you a SQL console where you can send your queries (in batch-mode, by terminating the batch with a GO on the last line):

  1. An existing connection was forcibly closed by the remote host

I have also found out that when querying the database from SSMS , if I query a table that has image/blob columns and if I include them in the query and if their values are not empty, then the connection between the SSMS and SQL Server is forcibly closed:


It appears to work with no problem from osql utility but from a Windows station where I have SSMS...well, you may encounter this unfortunate situation.

Later MS-SQL versions (eg. MS-SQL 2005,2008,etc)

SQL 2005 runs in top of .NET. This means you should firstly install .net on Linux and that's possible thanks to Mono Project. There are people who say they succeeded installing SQL2K8 on Linux (http://tenbulls.co.uk/2011/04/01/how-to-run-sql-server-on-linux/) so I guess it works (although I never tried anything else than SQL2K).

Recently (Nov 2016) I found out that Microsoft has planned to release the MS-SQL for other platforms like Linux (RedHat Ent, Ubuntu, SUSE) and MacOS. If interested then take a look at Microsoft official web page and also their presentation video.

Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.

 
The following two tabs change content below.
MS-SQL Server on Linux? Yes, it works!

Eugen Mihailescu

Founder/programmer/one-man-show at Cubique Software
Always looking to learn more about *nix world, about the fundamental concepts of math, physics, electronics. I am also passionate about programming, database and systems administration. 16+ yrs experience in software development, designing enterprise systems, IT support and troubleshooting.
MS-SQL Server on Linux? Yes, it works!

Latest posts by Eugen Mihailescu (see all)

Tagged on: , ,

31 thoughts on “MS-SQL Server on Linux? Yes, it works!

  1. Non-foe

    Hey, about your test result at the wine project, they can be somewhat harsh and tough about what is allowed, so please don't take it personally, there are many reasons for those rules beyond users not having to go to other sites like persistence and copyright.
    So please alter it and resubmit, it is an important result(for database testing and so forth). I will try it my self at the earliest opportunity.

  2. Jamie Moles

    Have you tried getting a newer version of MSSQL such as SQL Express 2005 or 2008 to work? Would be interested in your findings

    1. Eugen Mihailescu

      The problem with any MSSQL > 2K is that they are using .NET. Although one could use Mono (on Linux) to port an .NET apps (like SQL2K5, SQL2K8) on Linux, I'm not sure that it will work like a charm (in fact I have - sometimes - problems using SQL2K5/8 even on Windows, so ... no comment).
      Maybe I will give it a try sometimes.

  3. mugiseyebrows

    Good article. I make some experiments on linux mint and find out that DISABLEROLLBACK=1 needed in wine setup.exe step. Otherwise wine net start MSSQLSERVER will return error 'could not get handle to service'.

  4. Stefan Popescu

    This is one of the coolest things I have seen in a while! Thanks for posting this.
    I'm thinking to build a VM image with this stuff and make it publicly available...

  5. Mir

    Dear...Nice job.....but i am trying to install own my CENTOS6.4 but they give me errorzz....
    please check it...

    fixme:storage:create_storagefile Storage share mode not implemented.
    fixme:clusapi:OpenCluster ((null)) stub!
    fixme:clusapi:CloseCluster (0xdeadbeef) stub!
    fixme:clusapi:OpenCluster ((null)) stub!
    fixme:clusapi:CloseCluster (0xdeadbeef) stub!
    fixme:clusapi:OpenCluster ((null)) stub!
    fixme:clusapi:CloseCluster (0xdeadbeef) stub!
    fixme:clusapi:OpenCluster ((null)) stub!
    fixme:clusapi:CloseCluster (0xdeadbeef) stub!
    fixme:clusapi:OpenCluster ((null)) stub!
    fixme:clusapi:CloseCluster (0xdeadbeef) stub!
    fixme:clusapi:OpenCluster ((null)) stub!
    fixme:clusapi:CloseCluster (0xdeadbeef) stub!
    fixme:clusapi:OpenCluster (L"") stub!
    fixme:clusapi:ClusterOpenEnum (0xdeadbeef, 1) stub!
    fixme:clusapi:ClusterEnum (0xdeadbeef, 0, 0x7fd128, 0x7fd130, 128) stub!
    fixme:clusapi:CloseCluster (0xdeadbeef) stub!
    err:wineconsole:WCUSER_SetFont wrong font
    err:wineconsole:WCUSER_SetFont wrong font
    err:wineconsole:WCUSER_SetFont wrong font
    err:wineconsole:WCUSER_SetFont wrong font
    err:wineconsole:WCUSER_SetFont wrong font
    err:wineconsole:WCUSER_SetFont wrong font
    fixme:clusapi:OpenCluster (L"") stub!
    fixme:clusapi:ClusterOpenEnum (0xdeadbeef, 1) stub!
    fixme:clusapi:ClusterEnum (0xdeadbeef, 0, 0x33d40c, 0x33d414, 128) stub!
    fixme:clusapi:CloseCluster (0xdeadbeef) stub!
    fixme:setupapi:SetupAddInstallSectionToDiskSpaceListA Stub
    fixme:advapi:DecryptFileA ("C:\\users\\root\\Temp\\IXP001.TMP\\", 00000000): stub
    fixme:msi:get_duplicate_filename Unable to get destination folder, try AppSearch properties
    fixme:msi:get_duplicate_filename Unable to get destination folder, try AppSearch properties
    fixme:msi:ITERATE_DuplicateFiles We should track these duplicate files as well
    fixme:msi:ITERATE_DuplicateFiles We should track these duplicate files as well
    fixme:loadperf:UnloadPerfCounterTextStringsW (L"unlodctr.exe MSSQLSERVER", 0): stub
    fixme:loadperf:LoadPerfCounterTextStringsW (L"lodctr sqlctr.ini", 0): stub
    err:wineconsole:WCUSER_SetFont wrong font
    err:wineconsole:WCUSER_SetFont wrong font
    err:wineconsole:WCUSER_SetFont wrong font
    err:wineconsole:WCUSER_SetFont wrong font
    err:wineconsole:WCUSER_SetFont wrong font
    err:wineconsole:WCUSER_SetFont wrong font
    fixme:advapi:LsaOpenPolicy (L"SQLcentos",0x7fcdfc,0x00000810,0x7fcdf8) stub
    fixme:advapi:LsaClose (0xcafe) stub
    dwVersion is 0xa280105
    dwVersion is 0xa280105
    fixme:advapi:RegisterEventSourceW ((null),L"MSSQLSERVER"): stub
    fixme:service:SetServiceBits 0x122e38 00000004 1 0
    fixme:advapi:ReportEventW (0xcafe4242,0x0004,0x0002,0xc000429f,(nil),0x0002,0x00000024,0xd2d6a8,0xd2e140): stub
    fixme:advapi:ReportEventW (0xcafe4242,0x0004,0x0002,0xc000429f,(nil),0x0002,0x00000024,0xd2d6a8,0xd2e140): stub
    fixme:advapi:ReportEventW (0xcafe4242,0x0004,0x0002,0xc000429f,(nil),0x0002,0x00000024,0xd2d298,0xd2dd30): stub
    fixme:advapi:ReportEventW (0xcafe4242,0x0004,0x0002,0xc000429f,(nil),0x0002,0x00000024,0xd2ce48,0xd2d8e0): stub
    fixme:advapi:ReportEventW (0xcafe4242,0x0004,0x0002,0xc000429f,(nil),0x0002,0x00000024,0xd2ce30,0xd2d8c8): stub
    fixme:advapi:ReportEventW (0xcafe4242,0x0004,0x0002,0xc000429f,(nil),0x0002,0x00000024,0x1e5d20c,0x1e5dca4): stub
    fixme:advapi:RegisterTraceGuidsW (0x8787fd, 0x171c030, {f12b1984-4c42-11d3-ab7b-00c04f68fcdc}, 1, 0x820027e8, (null), (null), 0x171c050,): stub
    fixme:advapi:ReportEventW (0xcafe4242,0x0004,0x0002,0xc000429f,(nil),0x0002,0x00000024,0x205d484,0x205df1c): stub
    fixme:volume:GetVolumePathNameW (L"C:\\MSSQL\\Data\\tempdb.mdf", 0x21ecb38, 261), stub!
    fixme:volume:GetVolumePathNameW (L"C:\\MSSQL\\Data\\templog.ldf", 0x21ecb38, 261), stub!
    fixme:advapi:RegisterEventSourceA ((null),"MSSQLServer"): stub
    fixme:advapi:RegisterEventSourceW (L"",L"MSSQLServer"): stub
    fixme:ntdll:NtCreatePort (0x127264,0x205b02c,0,56,0x80000),stub!
    fixme:advapi:ReportEventA (0xcafe4242,0x0001,0x0008,0xc0004a43,(nil),0x0001,0x00000000,0x205b03c,(nil)): stub
    fixme:advapi:ReportEventW (0xcafe4242,0x0001,0x0008,0xc0004a43,(nil),0x0001,0x00000000,0x1279a0,(nil)): stub
    err:eventlog:ReportEventW L"ConnectionListen(Shared-Memory (LPC)) : Error 10055"
    fixme:ntdsapi:DsGetSpnA (0,"MSSQLSvc",(null),0,0,(nil),(nil),0x205ae54,0x205b060): stub!
    fixme:advapi:ReportEventA (0xcafe4242,0x0002,0x0008,0xc0004a43,(nil),0x0001,0x00000000,0x205b060,(nil)): stub
    fixme:advapi:ReportEventW (0xcafe4242,0x0002,0x0008,0xc0004a43,(nil),0x0001,0x00000000,0x127150,(nil)): stub
    fixme:thread:NtQueryInformationThread Cannot get kerneltime or usertime of other threads
    fixme:advapi:ReportEventW (0xcafe4242,0x0004,0x0002,0xc000429f,(nil),0x0002,0x00000024,0x2059dd8,0x205a870): stub
    fixme:advapi:ReportEventW (0xcafe4242,0x0001,0x0002,0x4000429c,(nil),0x0001,0x00000024,0x205dacc,0x205df88): stub
    err:eventlog:ReportEventW L"Error: 17826, Severity: 18, State: 1\r\nCould not set up Net-Library 'SSNETLIB'."
    fixme:advapi:ReportEventW (0xcafe4242,0x0001,0x0002,0xc000429f,(nil),0x0002,0x00000024,0x205d750,0x205e1e8): stub
    err:eventlog:ReportEventW L"17120"
    err:eventlog:ReportEventW L"SQL Server could not spawn FRunCM thread.\r\n"
    fixme:volume:GetVolumePathNameW (L"C:\\MSSQL\\Data\\tempdb.mdf", 0x234d548, 261), stub!
    fixme:volume:GetVolumePathNameW (L"C:\\MSSQL\\Data\\templog.ldf", 0x234d548, 261), stub!
    fixme:advapi:UnregisterTraceGuids 0: stub
    err:msi:ITERATE_Actions Execution halted, action L"ConfigServer.2D02443E_7002_4C0B_ABC9_EAB2C064397B" returned 1603
    err:msi:ITERATE_Actions Execution halted, action L"ExecuteAction" returned 1603
    fixme:advapi:LsaOpenPolicy ((null),0x8fd768,0x00000020,0x8fd748) stub
    fixme:advapi:LsaStorePrivateData (0xcafe,0x8fd75c,(nil)) stub
    fixme:advapi:LsaClose (0xcafe) stub
    fixme:advapi:LsaOpenPolicy ((null),0x8fd768,0x00000020,0x8fd748) stub
    fixme:advapi:LsaStorePrivateData (0xcafe,0x8fd75c,(nil)) stub
    fixme:advapi:LsaClose (0xcafe) stub
    fixme:advapi:LsaOpenPolicy ((null),0x8fd768,0x00000020,0x8fd748) stub
    fixme:advapi:LsaStorePrivateData (0xcafe,0x8fd75c,(nil)) stub
    fixme:advapi:LsaClose (0xcafe) stub
    fixme:msi:get_duplicate_filename Unable to get destination folder, try AppSearch properties
    fixme:msi:get_duplicate_filename Unable to get destination folder, try AppSearch properties
    err:rpc:I_RpcGetBuffer no binding
    err:rpc:I_RpcGetBuffer no binding
    err:rpc:I_RpcGetBuffer no binding
    err:rpc:I_RpcGetBuffer no binding

    i want to install it....please help me ....

    1. Eugen Mihailescu Post author

      I have no idea, it must be something related to Wine.
      Make sure you install MSDE on a clean Wine prefix. If you have used Wine before maybe you have set some Wine settings that are incompatible with MSDE. I really don't know but it would be a good idea to test this setup with a clean Wine prefix.
      Try to trace your Wine related issue on Google.
      BTW: you are running the MSDE2000 setup and not SQLExpress 200x (x>5) or something, right?

      1. mir

        Actually ...when i select DLL/service....(mda27)...they also give me this error err:eventlog:ReportEventW L"SQL Server could not spawn FRunCM thread.\r\n"
        it's means MSDA is not install properly....but who can i install..? they give me path were you download and where you paste and then again run winetrick.... but after this they show me you successfully install ...but when i run this command...
        wine ~/.wine/drive_c/MSDERelA/setup.exe SAPWD="" DISABLENETWORKPROTOCOLS=0 SECURITYMODE=SQL (using root permission)
        they show me error that i send you early...please guide what i do....are i go to centos.....or using other linux flavour..?

        1. Eugen Mihailescu Post author

          1) Try to start the setup with a clean Wine prefix. This will delete all applications/settings that you have installed with wine (run winetricks -> select default wineprefix -> DELETE ALL DATA INSIDE WINEPREFIX).
          2) make sure you follow all steps from the article above
          Note: I've mentioned in the article that "it's possible that the setup crashes; don't worry, run the following command:
          cp ~/.wine/drive_c/users/eugen/Temp/SqlSetup/Temp/*.* ~/.wine/drive_c/windows/system32/"

          To run MSDE on Linux is not a piece of cake but also it's not rocket science.

          1. mir

            Thank you....for help me ...and reply.....Actually .....i am in doubt Centos is not compatible...but hope for good....so i try again...And hope to installl ....but MSDA...is not install.....so please can you explain what is mda? i explain my view....i have server 2008 server that run sql2000...so i want server 2008 to primary ....and linux sql is secondary....but.....they not install ....any key point that you give me...please share it....

  6. Eugen Mihailescu Post author

    When you say "MDA" you mean "MDAC", right? If that's the case then read more about what is MDAC here.
    MDAC2.7 (or greater) is required if you want to run some applications (within CentOS) that connect directly to the MS-SQL instance. Keep in mind that a client application can connect to MS-SQL instance either via MDAC or ODBC. MDAC drivers are better than ODBC.
    Note that I have tested only MSDE2000 and not any other Microsoft SQL version. So stick to MSDE2000 only.
    I don't have time right now to test this configuration on CentOS but I think it should work.

  7. mir

    if i want to run ODBC...?then what is method....means in DLL/serverice they ODBC have no option....so please explain what i do..? are i install odbc2unix...?install like that rpm..? try to other?...and last i try to install MSDE2000A.exe.....after delete all things...but they not working....and show same error that i send you early....don't no why they do this..but i think.....some think missing/.... please help us....to sort out this problem...

  8. Eugen Mihailescu Post author

    If you want to connect the MS-SQL using an program that is installed on Wine (also an Windows application) the you have to install ODBC within Wine.

    If you want to connect the MS-SQL using a program that is installed on Linux then you will need some drivers (eg. unixODBC or something) that allows you to communicate with MS-SQL.

    I don't know if I can help you further with your setup because there could be hundreds reason why MSDE does not install properly on Wine under CentOS. What I can do to help you is to create a VM image that runs a Linux flavor (like CentOS or Gentoo or ArchLinux) and in top of this I could install Wine + MSDE2000. So you can take that VM image and play little bit with it. But anyway, this will be a future plan because unfortunately I don't have much time right now.

    1. mir

      Actually, i explain my setup.....i have window server 2008...that run MSSQL2000...and it contain ERP....so i want to install MSSQL 2000 in linux....to set it as secondary database server.....but...centos is not suitable for installation MSDE2000....i don't know how i can i do this...i need a help that do this thing.....just help me.....what is requirment to install MSDE2000 in centos....ACtually, when i install MSDE2000 using wine...they give me error....that i tell you early....i install .net2.....and visual basic...but they don't install..........................if you have little bit time then please tell me which software is prerequiste MSDE2000 for centos...i need it hardly...i am using Virtual Machine this time for experiment...if i am successfully create this...then implement it into environment...you help is very important for me....And thanks for all that you done...for me...

  9. MrO

    I don't mean to be rude, this is a great, very technical and well written guide.

    But why on earth would you ever do this?
    MariaDB or postgres are fantastic products and actually work with linux out of the box. I can imagine there may be unforseen issues with running it under wine. I'd never run a production database like this

    1. Eugen Mihailescu Post author

      No one says that you have to write a software that uses a MSSQL database on Linux. But if you have a Win-32bit application that uses MSSQL and you want to run it on Linux then it's good to know that Linux to some extent will allow you doing that. I would definitely use SQLite/MySQL/PostgreSQL/whatever that MSSQL if I would to write a Linux app. But I wanted to present a solution for these people that need it badly.

    1. Eugen Mihailescu Post author

      Why not? What makes Ubuntu so special anyway? Ubuntu is nothing else than the same GNU Linux system which on top have a windowing system (such as Gnome or whatever you like to install) and then a pre-installed set of applications/tools.

      So in short, Yes, it should work.

      1. Andreas Braml

        Lease note: The report in the link was an April Fool's Joke 😀

        To my knowledge, SQL2K5 still doesn't work on Wine. Neither does 2K8.

        Maybe worth a try on the new Wine 1.8 with it's .NET improvements, though?

    1. Eugen Mihailescu Post author

      There is no Linux such Oracle Linux. I mean there is a product called Oracle Linux but...I can prepare a distro by myself and call it Eugen Linux but at the end of the day it is just the old Linux!
      What is behind this Oracle Linux is what everybody knows as the GNU Linux system.

      This remark is very important! From now on we regard the Oracle Linux as a Linux. Thus, it must support both Wine project as well as Mono project. By using Wine project you can install the MSDE2k on your Linux. By using Mono project you can install MSDE2k5+ on your Linux. Whatever Linux distro you may have.

      Note that I never tried this (as I don't run all Linux distro out there) but my guts tell me that it should work.

  10. meghana

    Hai i want to run ms sql in ubuntu but i have windows ms sql softare is there .

    so i have installed wine software

    then next what i need to do

    help me!!!!!!!!!!!

    if any one knows

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: