13

I am installing TeamCity on a Windows 2012 Server. I'm at the database connection setup screen but getting this error.

"SQL error when doing: Taking a connection from the data source: no sqljdbc_auth in java.library.path"

I've copied the sqljdbc_auth.dll to the C:\Windows\System32 folder and added a system environment variable java.library.path that points to this folder.

joe_young
  • 4,107
  • 2
  • 27
  • 38
DomBurf
  • 2,452
  • 5
  • 36
  • 71

7 Answers7

18

Teamcity installs the 32-bit version even if you're on a 64-bit platform unless you deliberately use 64-bit. So I am just going to give you the 32-bit instructions for using Windows authentication with Teamcity SQL database setup. The instructions are the same for the 64-bit setup, just change x86 to x64

  1. Create an empty database in SQL server
  2. Make sure the Windows account configured on the TeamCity service(s) have access to the database
  3. Copy sqljdbc42.jar to <TeamCity_data_dir>\lib\jdbc\sqljdbc42.jar
  4. Copy auth\x86\sqljdbc_auth.dll from the Microsoft download to <TeamCity_data_dir>\lib\sqljdbc_auth.dll
  5. Open System > Advanced System Settings > Environment Variables and add a System variable TEAMCITY_SERVER_OPTS set to the value -Djava.library.path=<TeamCity_data_dir>\lib or run setx TEAMCITY_SERVER_OPTS=-Djava.library.path=<TeamCity_data_dir>\lib
  6. Click OK on all dialogs and restart the Teamcity services.

Now you can connect Teamcity to the SQL server using Windows Authentication after which the wizard will create the database.

Edit: January 27, 2020

With the 2019.2.1 update I've had to move the sql_jdbcauth.dll file to <TeamCity_data_dir>\system\caches\jdbc\native\windows-i386 This could be just a bug in the upgrade process.

Community
  • 1
  • 1
Bron Davies
  • 5,930
  • 3
  • 30
  • 41
  • 4
    this should be how the TeamCity instructions are written, not their current documentation which got me nowhere.. thanks a lot for this answer – Pricey Aug 23 '16 at 16:11
  • 3
    Step 5 is confusing. Server 2016 has an improved dialog box that requires you to separate the variable name and variable value. The correct variable name is `TEAMCITY_SERVER_OPTS` and the correct variable value is `-Djava.library.path=\lib`, of course substituting `` for your actual teamcity data dir path. – Sam Rueby Jan 17 '18 at 21:25
7

This

http://www.mikeobrien.net/blog/teamcity-sqlserver-integrated-security

helped me.

I used the JDBC 4.1 version.

Tomas Kubes
  • 23,880
  • 18
  • 111
  • 148
Motlicek Petr
  • 767
  • 9
  • 10
  • I upvoted as it helped me a lot - but I would suggest putting some more info beside link. All is summarized to this: replace TC jre with x64 jre. – Grzegorz W Jan 14 '16 at 21:17
  • 3
    Or if you're running on 32 bit, just drop the x86 version of `sqljdbc_auth.dll` (from the jdbc download) into `\bin` – Brian Lacy Jun 16 '16 at 00:11
  • @BrianLacy this is the only thing that worked for me, thanks. You should add it as an answer. – demoncodemonkey Aug 07 '16 at 09:15
6

I managed to resolve the issue by using SQL Server authentication instead of Windows authentication during the database configuration setup. Not sure why this should have fixed the error as it relates to a Java environment variable, but I can only assume that the error was generated by it's failure to login to the database and for some reason threw an unrelated error instead.

This appears to be an error with TeamCity throwing the wrong error message. If you get this error, try switching to SQL Server authentication.

DomBurf
  • 2,452
  • 5
  • 36
  • 71
  • Windows authentication has specific configuration requirements - access to the Microsoft provided DLL to support it. Normal SQL authentication does not require this. See my answer. – Bron Davies Feb 18 '16 at 06:11
  • You have to provide path to dll `-Djava.library.path=path/to/dll`, please read more here https://stackoverflow.com/a/50115530/6655459 – rafalkasa May 01 '18 at 11:22
  • Switching from Windows Authentication to SQL Server authentication just to fix a file not found error is like using a cannon to kill a mosquito – janv8000 Mar 20 '19 at 07:34
6

If you're running on 32-bit, you can just copy the x86 version of sqljdbc_auth.dll (from the jdbc download) into <TeamCityProgramDir>\bin.

Brian Lacy
  • 18,785
  • 10
  • 55
  • 73
  • 2
    This worked for me in the migration step. But when running TeamCity afterwards, it still couldn't find the file. So I ended up copying the file to `TeamCityProgramDir\bin` AND `TeamCityProgramDir\lib`, and it's all fine now. – demoncodemonkey Aug 09 '16 at 05:47
  • 1
    this should be the answer! – Miguel Aug 19 '16 at 14:50
  • Files in the `bin` folder get moved during automatic TeamCity updates: _[2019-03-19 16:18:14,375] INFO - jetbrains.buildServer.UPDATE - Moving C:\TeamCity\bin\sqljdbc_auth.dll to .old_ – janv8000 Mar 20 '19 at 07:36
1

You should check your TeamCity server log. Mine (located at c:\TeamCity\logs\teamcity-server.log) mentions the following:

[2019-03-20 07:54:56,045] INFO - jetbrains.buildServer.STARTUP - Native library sqljdbc_auth.dll was not found under either E:\BuildServer\lib\jdbc\native\windows-i386 or E:\BuildServer\lib\jdbc\native; will continue looking in sun.boot.library.path and java.library.path.

After putting the sqljdbc_auth.dll library in E:\BuildServer\lib\jdbc\native\windows-i386 and restarting the service everything was fine and dandy; without having to meddle with bin folders (they get reset during TC upgrades) or having to define environment variables.

janv8000
  • 1,569
  • 2
  • 19
  • 33
0

In my case it didn't worked because there were some files from previous install and version TeamCity isntallation. I uninstalled TeamCity, deleted all TeamCity folders and installed again. Then it worked like a charm.

Tomas Kubes
  • 23,880
  • 18
  • 111
  • 148
0

I was running into this issue today with TeamCity 10.x, with bundled Java, and I wanted to migrate an existing, internal, database to SQL Server.

  1. Follow Setting up TeamCity with MS SQL Server until you need to setup the JDBC Driver.
  2. Log into your TeamCity server with the same Windows account you setup SQL Server with.
  3. With the current version they say to download the 6.0+ driver, but then reference the 4.x version. You want the version at Downloads\Microsoft JDBC Driver 6.2 for SQL Server\sqljdbc_6.2\enu\mssql-jdbc-6.2.2.jre8.jar, and to copy it to C:\ProgramData\JetBrains\TeamCity\lib\jdbc\mssql-jdbc-6.2.2.jre8.jar.
  4. From that same 6.x driver download, copy Downloads\Microsoft JDBC Driver 6.2 for SQL Server\sqljdbc_6.2\enu\auth\x86\sqljdbc_auth.dll to C:\ProgramData\JetBrains\TeamCity\lib\sqljdbc_auth.dll.
  5. Add a new System Environment Variable called TEAMCITY_SERVER_OPTS with the value of -Djava.library.path=C:\ProgramData\JetBrains\TeamCity\lib.
  6. So that the MaintainDB tool works, add another System Environment Variable called TEAMCITY_MAINTAINDB_OPTS with the same value (-Djava.library.path=C:\ProgramData\JetBrains\TeamCity\lib).

Now you can run MaintainDB without getting an error about the sqljdbc_auth.dll not being in the JAVA library path.

See Creating Backup via maintainDB command-line tool - maintainDB Startup Options for why both environment variables need to be set.

James Skemp
  • 8,018
  • 9
  • 64
  • 107