4

I try to connect MSSQL from macOS. My PHP/Laravel application runs in macOS.

Based on this link, I ran following two commands:

# sudo pecl install sqlsrv
# sudo pecl install pdo_sqlsrv

And i got message saying it is already installed.

pecl/pdo_sqlsrv is already installed and is the same as the released version 4.3.0
install failed.

But when I try to connect mssql,

#php artisan migrate:install

I get the following exception:

Illuminate\Database\QueryException]                                                                                                   
  SQLSTATE[01000]: [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (SQL: create table "migrat  
  ions" ("id" int identity primary key not null, "migration" nvarchar(191) not null, "batch" int not null))                              



  [PDOException]                                                                                              
  SQLSTATE[01000]: [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found 

What else I need to install? My php version is 7.1


Issue I get when I try

# brew install msodbcsql 
Error: Formulae found in multiple taps: 
 * microsoft/msodbcsql/msodbcsql
 * microsoft/mssql-preview/msodbcsql

Please use the fully-qualified name e.g. `microsoft/msodbcsql/msodbcsql` to refer the formula.

So changed to:

# brew install  microsoft/msodbcsql/msodbcsql

Then I'm getting this;

Do you accept the license terms? (Enter YES or NO)
YES
==> odbcinst -u -d -n "ODBC Driver 13 for SQL Server"
==> odbcinst -i -d -f ./odbcinst.ini
Last 15 lines from /Users/ratha/Library/Logs/Homebrew/msodbcsql/02.odbcinst.ini:
2017-08-03 14:03:06 +1000

odbcinst -i -d -f ./odbcinst.ini

odbcinst: SQLInstallDriverEx failed with Invalid install path.

If reporting this issue please do so to (not Homebrew/brew or Homebrew/core):
microsoft/msodbcsql

/usr/local/Homebrew/Library/Homebrew/utils/github.rb:226:in `raise_api_error': curl failed!  (GitHub::Error)
curl: (22) The requested URL returned error: 422 Unprocessable Entity
curl: (3) <url> malformed
    from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:184:in `open'
    from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:233:in `issues_matching'
    from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:272:in `issues_for_formula'
    from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:369:in `fetch_issues'
    from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:365:in `issues'
    from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:419:in `dump'
    from /usr/local/Homebrew/Library/Homebrew/brew.rb:133:in `rescue in <main>'
    from /usr/local/Homebrew/Library/Homebrew/brew.rb:26:in `<main>
kenorb
  • 155,785
  • 88
  • 678
  • 743
Ratha
  • 9,434
  • 17
  • 85
  • 163

3 Answers3

4

You need to install ODBC with --no-sandbox as brew install --no-sandbox msodbcsql

https://github.com/Microsoft/homebrew-mssql-release/issues/1

Genjutsu
  • 223
  • 2
  • 12
2

Reinstall the packages:

brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release
ACCEPT_EULA=y brew reinstall --no-sandbox msodbcsql mssql-tools

If it's still happening, run:

cp -v "$(brew list msodbcsql | grep odbcinst.ini$)" ~/.odbcinst.ini

to copy the INI file which defines the location of SQL ODBC driver.

Or create the file manually, e.g.

printf "[ODBC Driver 13 for SQL Server]\nDescription=Microsoft ODBC Driver 13 for SQL Server\nDriver=/usr/local/lib/libmsodbcsql.13.dylib\n" >> ~/.odbcinst.ini

Bug report: SQL Server : Can't open lib 'ODBC Driver 13 for SQL Server'.

See: Installing the Microsoft ODBC Driver for SQL Server on Linux and macOS.

If you're using Anaconda, checkout this issue: ODBC Driver 13 for SQL Server can't open lib.

kenorb
  • 155,785
  • 88
  • 678
  • 743
1

I believe there is a prerequisite of "Microsoft ODBC Driver 13" that hasn't been installed on the Mac.

According to this blog post, Microsoft appears to be working on a Mac version of the driver.

Since you are working with Laravel; first try;

composer update && upgrade

from the root directory of the web application to see if it can pull all the dependencies automatically.

If not try installing the driver as instructed in the link provided above.

If you already have the ODBC driver installed, it should be located in the following directory on your Mac;

/Library/ODBC/

Cheers.

Manu
  • 48
  • 7
  • Thanks. i follwed above blog post and I get issue at this line; brew install msodbcsql . I have edited my question with the issue I face – Ratha Aug 03 '17 at 04:08
  • 1
    You may need [ODBC Manager for Mac](http://www.odbcmanager.net/). It used to ship with OSX, but the newer OS doesn't have it. Install and then try again? – Manu Aug 03 '17 at 04:26
  • I did. But same issue again :( – Ratha Aug 03 '17 at 04:29
  • @Genjutsu answer should carry you the rest of the way there. Good luck. – Manu Aug 04 '17 at 03:39