findmypast-oss / mssql_ecto

Ecto adapter for Mssqlex
Apache License 2.0
49 stars 20 forks source link

Installing Erlang ODBC on Windows 2012 R2 #21

Closed puruzio closed 7 years ago

puruzio commented 7 years ago

I'm having trouble installing Erlang ODBC on Windows, and I suspect many Windows users struggle with the same issue.

There is very little documentation on the internet about how to install this Erlang library. I found this (http://erlang.org/documentation/doc-5.1/lib/odbc-0.9.1/doc/html/OdbcCompileWindows.html) and tried to follow it.

I was able to find the erl8.2\lib\odbc-2.12\src folder on my C: drive. This is where the instruction seems to expect this “Makefile” to exist but I don’t see such file there. Instead there are these 4 files only.

odbc_app.erl odbc.internal.hrl odbc_sup.erl odbc.erl

Your help will be greatly appreciated. Thank you.

shdblowers commented 7 years ago

If I recall correctly we did manage to get mssql_ecto working correctly on Windows when we were doing some testing during the creation of this library, however this would have been on Window 8 or 10.

So, I don't know how to install it correctly for 2012.

My advice would be to either run your Elixir service inside a docker container (take a look at our Dockerfile for what that would look like) or run your Elixir service on a separate server and talk to your db over the network.

puruzio commented 7 years ago

Can you share how you did it on Windows 8 or 10? I doubt it will be too different for 2012. Did you have Makefile in the Erlang ODBC source folder?

Unfortunately using Docker isn't possible in my case.

jbachhardie commented 7 years ago

You most likely already have erlang-odbc installed. Most OTP binaries for Windows include it in their bundle. To check, run

iex(1)> :odbc.start
:ok

If you don't have it you should try uninstalling Elixir and Erlang and re-installing Elixir from the official installer or Chocolatey package manager since they definitely serve bundles that have the ODBC application in them.

This is why the README states it "might" require additional packages. Installations for Windows and MacOS tend to have it bundled, not so installations for Debian or Ubuntu.

puruzio commented 7 years ago

Thank you.

:odbc.start does return :ok on my machine, which is great.

How do I start :odbc in my Elixir/Phoenix app ? I tried to put it in mix.exs under applications list, but then I get

(Mssqlex.Error) [Microsoft] [ODBC Driver Manager] Data source name not found 
and no default driver specified Connection to database failed. 
| ODBC_CODE IM002 | SQL_SERVER_CODE 0

I already have the following in dev.exs based on the instruction in ReadMe, but Mssqlex might not be seeing it.

config :myapp, MyApp.MSRepo,
   adapter: MssqlEcto,
   username: xxxxxx,
   password: xxxxxx,
  database: MyDatabase,
  hostname: xxxxxxx

and the following in config.exs

config :myapp, 
   ecto_repos: [MyApp.Repo, MyApp.MSRepo]  #Repo is a postgrex repo
shdblowers commented 7 years ago

There is a config option called :odbc_driver, this defaults to: {ODBC Driver 13 for SQL Server}. Which works if you follow the instructions with installation on Linux, but probably not for Windows.

This will have to change to the Windows ODBC driver you are using.

shdblowers commented 7 years ago

Here is a link to help you find the ODBC driver you have installed: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/check-the-odbc-sql-server-driver-version-windows

puruzio commented 7 years ago

Thank you so much for your help!!! Installing SQL Server driver 13 did the trick.

shdblowers commented 7 years ago

No problem @puruzio

Was there anything missing from the README that would have solved your problem without having to open an issue?

puruzio commented 7 years ago

I had to add :odbc to the application list in mix.exs to avoid "odbc_not_started" error at mix phx.server. Also it would help to tell people it's SQL Server ODBC 13 that they need to install. In my case, I already had "SQL Server 6.3" in the list of ODBC drivers and I originally thought that would meet the prerequisite of a SQL server ODBC driver, which it didn't.

On Wed, Aug 9, 2017 at 3:14 AM, Steven Blowers notifications@github.com wrote:

No problem @puruzio https://github.com/puruzio

Was there anything missing from the README that would have solved your problem without having to open an issue?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/findmypast-oss/mssql_ecto/issues/21#issuecomment-321214357, or mute the thread https://github.com/notifications/unsubscribe-auth/ABGPLnYAFFbHIs8voxKRRy24g4Ft743uks5sWYaUgaJpZM4OuYbQ .