{"id":858,"date":"2016-06-15T20:06:38","date_gmt":"2016-06-16T03:06:38","guid":{"rendered":"http:\/\/www.sqldbpros.com\/?p=858"},"modified":"2016-06-16T12:15:19","modified_gmt":"2016-06-16T19:15:19","slug":"dbfit-and-sql-server-missing-jdbc-driver","status":"publish","type":"post","link":"http:\/\/sqldbpros.com\/wordpress\/2016\/06\/dbfit-and-sql-server-missing-jdbc-driver\/","title":{"rendered":"DBFit and SQL Server and JDBC: Missing JDBC Driver."},"content":{"rendered":"<p>If you are using the java version of DBFit and you want to connect to SQL Server you may start to think it can't be done. Fear not! It is possible! I'll summarize the required steps as well as all the error messages I received along the way.<\/p>\n<p>Running through these steps will enable you to connect to a sql server named instance using integrated security.<\/p>\n<p>(If you've already got this under control then go ahead and <a href=\"http:\/\/www.sqldbpros.com\/2016\/06\/dbfit-and-sql-server-how-to-connect-and-create-your-first-test\/\">Create Your First Test Using SQL Server and DBFit<\/a>!)<\/p>\n<h3>Step 1: Download the JDBC SQL Server Driver<\/h3>\n<p>You need to download the JDBC SQL Server Driver. You can get it at <a href=\"https:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=11774\" target=\"_blank\">Microsoft JDBC Drivers for SQL Server<\/a>.<\/p>\n<p>The <a href=\"http:\/\/dbfit.github.io\/dbfit\/docs\/faq.html\">DBFit FAQ<\/a> includes the following info:<\/p>\n<blockquote><p>Deploy the JAR in the same folder as dbfit-XXX.jar. If you specify the full JDBC connection string explicitly, use Microsoft\u2019s driver in JDBC URL. DbFit does not support 3rd party SQL Server drivers at the moment.<\/p><\/blockquote>\n<p>To be more specific this means that once you've downloaded the JDBC driver and unzipped them, find the file called sqljdbc4.jar and copy it into the DBFit directory called \"lib\" (..\\DBFit\\lib\\)<\/p>\n<p>If it's missing you'll see a mess of an error message like this:<\/p>\n<pre>dbfit.SqlServerTest\r\n\r\njava.lang.Error: Cannot load SqlServer database driver com.microsoft.sqlserver.jdbc.SQLServerDriver. Is the JDBC driver on the classpath?\r\n\tat dbfit.api.DbEnvironmentFactory$EnvironmentDescriptor.checkDriver(DbEnvironmentFactory.java:45)\r\n\tat dbfit.api.DbEnvironmentFactory$EnvironmentDescriptor.createEnvironmentInstance(DbEnvironmentFactory.java:60)\r\n\tat dbfit.api.DbEnvironmentFactory.createEnvironmentInstance(DbEnvironmentFactory.java:102)\r\n\tat dbfit.api.DbEnvironmentFactory.newEnvironmentInstance(DbEnvironmentFactory.java:106)\r\n\tat dbfit.SqlServerTest.(SqlServerTest.java:5)\r\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\r\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)\r\n\tat sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)\r\n\tat java.lang.reflect.Constructor.newInstance(Unknown Source)\r\n\tat java.lang.Class.newInstance(Unknown Source)\r\n\tat fit.FixtureClass.newInstance(FixtureClass.java:24)\r\n\tat fit.FixtureLoader.instantiateFixture(FixtureLoader.java:62)\r\n\tat fit.FixtureLoader.instantiateFirstValidFixtureClass(FixtureLoader.java:84)\r\n\tat fit.FixtureLoader.disgraceThenLoad(FixtureLoader.java:44)\r\n\tat fit.Fixture.loadFixture(Fixture.java:142)\r\n\tat fit.Fixture.getLinkedFixtureWithArgs(Fixture.java:134)\r\n\tat fit.Fixture.doTables(Fixture.java:79)\r\n\tat fit.FitServer.process(FitServer.java:81)\r\n\tat fit.FitServer.run(FitServer.java:56)\r\n\tat fit.FitServer.main(FitServer.java:41)\r\nCaused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver\r\n\tat java.net.URLClassLoader.findClass(Unknown Source)\r\n\tat java.lang.ClassLoader.loadClass(Unknown Source)\r\n\tat sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)\r\n\tat java.lang.ClassLoader.loadClass(Unknown Source)\r\n\tat java.lang.Class.forName0(Native Method)\r\n\tat java.lang.Class.forName(Unknown Source)\r\n\tat dbfit.api.DbEnvironmentFactory$EnvironmentDescriptor.checkDriver(DbEnvironmentFactory.java:43)\r\n\t... 19 more\r\n\r\n<\/pre>\n<h3>Step 2: Make sure SQL Server Browser is running<\/h3>\n<p>If you are connecting to a named instance of SQL Server then the next step is to make sure that SQL Server Browser service is running. You should already have it installed, just go to Services (press the Windows Button+R and type services.msc). Right click on SQL Server Browser\u00a0 and select \"Start\".<\/p>\n<p>If the SQL Server Browser Service is not running you'll see the following message:<\/p>\n<pre>Query\r\n\r\njava.lang.IllegalArgumentException: No open connection to a database is available. Make sure your database is running and that you have connected before performing any queries.\r\n\tat dbfit.api.AbstractDbEnvironment.checkConnectionValid(AbstractDbEnvironment.java:237)\r\n\tat dbfit.api.AbstractDbEnvironment.getConnection(AbstractDbEnvironment.java:162)\r\n\tat dbfit.api.AbstractDbEnvironment.createStatementWithBoundFixtureSymbols(AbstractDbEnvironment.java:108)\r\n\tat dbfit.fixture.Query.getDataTable(Query.java:43)\r\n\tat dbfit.fixture.RowSetFixture.doRows(RowSetFixture.java:92)\r\n\tat fit.Fixture.doTable(Fixture.java:156)\r\n\tat fitlibrary.traverse.AlienTraverseHandler.doTable(AlienTraverseHandler.java:21)\r\n\tat fitlibrary.traverse.workflow.DoTraverseInterpreter.interpretWholeTable(DoTraverseInterpreter.java:104)\r\n\tat fitlibrary.traverse.workflow.DoTraverseInterpreter.interpretWholeTable(DoTraverseInterpreter.java:89)\r\n\tat fitlibrary.DoFixture.interpretWholeTable(DoFixture.java:73)\r\n\tat fitlibrary.suite.InFlowPageRunner.run(InFlowPageRunner.java:27)\r\n\tat fitlibrary.DoFixture.interpretTables(DoFixture.java:42)\r\n\tat dbfit.DatabaseTest.interpretTables(DatabaseTest.java:26)\r\n\tat fit.Fixture.doTables(Fixture.java:81)\r\n\tat fit.FitServer.process(FitServer.java:81)\r\n\tat fit.FitServer.run(FitServer.java:56)\r\n\tat fit.FitServer.main(FitServer.java:41)\r\n<\/pre>\n<h3>Step 3: add the sqljdbc_auth.dll<\/h3>\n<p>If like most of us you're using integrated security with SQL Server you'll need to add the sqljdbc_auth.dll into your java directory. Go back to the\u00a0 your sqljdbc_6.0 directory and track down sqljdbc_auth.dll. Mine was in the following location: ..\\sqljdbc_6.0\\enu\\auth\\x86 . Copy sqljdbc_auth.dll into your java bin directory. The path for mine was C:\\Program Files (x86)\\Java\\jre1.8.0_91\\bin.<\/p>\n<p>If this file is missing you'll get the error message below. I managed to crack this one with the help of a <a href=\"https:\/\/groups.google.com\/forum\/#!topic\/dbfit\/2_qf-UyHPt0\" target=\"_blank\">google groups post by Yavor Nikolov<\/a> where someone else was reporting the same issue.<\/p>\n<pre>Connect\r\n\r\njava.lang.UnsatisfiedLinkError: no sqljdbc_auth in java.library.path\r\n\tat java.lang.ClassLoader.loadLibrary(Unknown Source)\r\n\tat java.lang.Runtime.loadLibrary0(Unknown Source)\r\n\tat java.lang.System.loadLibrary(Unknown Source)\r\n\tat com.microsoft.sqlserver.jdbc.AuthenticationJNI.(AuthenticationJNI.java:35)\r\n\tat com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2229)\r\n\tat com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)\r\n\tat com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220)\r\n\tat com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)\r\n\tat com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)\r\n\tat com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)\r\n\tat com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)\r\n\tat com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)\r\n\tat com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)\r\n\tat java.sql.DriverManager.getConnection(Unknown Source)\r\n\tat java.sql.DriverManager.getConnection(Unknown Source)\r\n\tat dbfit.api.AbstractDbEnvironment.connect(AbstractDbEnvironment.java:51)\r\n\tat dbfit.environment.SqlServerEnvironment.connect(SqlServerEnvironment.java:53)\r\n\tat dbfit.api.AbstractDbEnvironment.connect(AbstractDbEnvironment.java:57)\r\n\tat dbfit.DatabaseTest.connect(DatabaseTest.java:52)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\r\n\tat java.lang.reflect.Method.invoke(Unknown Source)\r\n\tat fitlibrary.closure.MethodClosure.invoke(MethodClosure.java:35)\r\n\tat fitlibrary.closure.MethodClosure.invokeTyped(MethodClosure.java:28)\r\n\tat fitlibrary.closure.CalledMethodTarget.invokeTyped(CalledMethodTarget.java:77)\r\n\tat fitlibrary.closure.CalledMethodTarget.invokeTyped(CalledMethodTarget.java:95)\r\n\tat fitlibrary.closure.CalledMethodTarget.invokeAndWrap(CalledMethodTarget.java:358)\r\n\tat fitlibrary.traverse.workflow.caller.ActionCaller.run(ActionCaller.java:37)\r\n\tat fitlibrary.traverse.workflow.DoTraverseInterpreter.interpretRow(DoTraverseInterpreter.java:176)\r\n\tat fitlibrary.traverse.workflow.DoTraverseInterpreter.interpretWholeTable(DoTraverseInterpreter.java:96)\r\n\tat fitlibrary.traverse.workflow.DoTraverseInterpreter.interpretWholeTable(DoTraverseInterpreter.java:89)\r\n\tat fitlibrary.DoFixture.interpretWholeTable(DoFixture.java:73)\r\n\tat fitlibrary.suite.InFlowPageRunner.run(InFlowPageRunner.java:27)\r\n\tat fitlibrary.DoFixture.interpretTables(DoFixture.java:42)\r\n\tat dbfit.DatabaseTest.interpretTables(DatabaseTest.java:26)\r\n\tat fit.Fixture.doTables(Fixture.java:81)\r\n\tat fit.FitServer.process(FitServer.java:81)\r\n\tat fit.FitServer.run(FitServer.java:56)\r\n\tat fit.FitServer.main(FitServer.java:41)\r\n\r\n\r\n<\/pre>\n<h3>Test It!<\/h3>\n<p>Once these three steps were complete I was able to successfully connect to a named instance of SQL Server and run a quick test query. Hooray! (Need help with your first test? Check out this little DBFit tutorial on <a href=\"http:\/\/www.sqldbpros.com\/2016\/06\/dbfit-and-sql-server-how-to-connect-and-create-your-first-test\/\">Creating Your First DBFit Test Using SQL Server<\/a>)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-866\" src=\"http:\/\/www.sqldbpros.com\/wordpress\/wp-content\/uploads\/2016\/06\/DBFit_SQLServer_JDBC.png\" alt=\"DBFit SQLServer Java and JDBC\" width=\"500\" height=\"312\" srcset=\"http:\/\/sqldbpros.com\/wordpress\/wp-content\/uploads\/2016\/06\/DBFit_SQLServer_JDBC.png 500w, http:\/\/sqldbpros.com\/wordpress\/wp-content\/uploads\/2016\/06\/DBFit_SQLServer_JDBC-300x187.png 300w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<h3>Other Errors: Java Runtime Environment (JRE) version 1.8 is not supported by this driver. Use the sqljdbc4.jar<\/h3>\n<p>Whoops. I had copied all the sqljdbc jar files into the lib directory. The only one that is needed is sqljdbc4.jar. You can delete sqljdbc.jar, sqljdbc41.jar, sqljdbc42.jar from DBFit\\lib\\ . Leave only sqljdbc4.jar.<\/p>\n<pre>java.lang.UnsupportedOperationException: Java Runtime Environment (JRE) version 1.8 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.\r\n\tat com.microsoft.sqlserver.jdbc.SQLServerConnection.(SQLServerConnection.java:304)\r\n\tat com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1011)\r\n\tat java.sql.DriverManager.getConnection(Unknown Source)\r\n\tat java.sql.DriverManager.getConnection(Unknown Source)\r\n\tat dbfit.api.AbstractDbEnvironment.connect(AbstractDbEnvironment.java:51)\r\n\tat dbfit.environment.SqlServerEnvironment.connect(SqlServerEnvironment.java:53)\r\n\tat dbfit.api.AbstractDbEnvironment.connect(AbstractDbEnvironment.java:57)\r\n\tat dbfit.DatabaseTest.connect(DatabaseTest.java:52)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\r\n\tat java.lang.reflect.Method.invoke(Unknown Source)\r\n\tat fitlibrary.closure.MethodClosure.invoke(MethodClosure.java:35)\r\n\tat fitlibrary.closure.MethodClosure.invokeTyped(MethodClosure.java:28)\r\n\tat fitlibrary.closure.CalledMethodTarget.invokeTyped(CalledMethodTarget.java:77)\r\n\tat fitlibrary.closure.CalledMethodTarget.invokeTyped(CalledMethodTarget.java:95)\r\n\tat fitlibrary.closure.CalledMethodTarget.invokeAndWrap(CalledMethodTarget.java:358)\r\n\tat fitlibrary.traverse.workflow.caller.ActionCaller.run(ActionCaller.java:37)\r\n\tat fitlibrary.traverse.workflow.DoTraverseInterpreter.interpretRow(DoTraverseInterpreter.java:176)\r\n\tat fitlibrary.traverse.workflow.DoTraverseInterpreter.interpretWholeTable(DoTraverseInterpreter.java:96)\r\n\tat fitlibrary.traverse.workflow.DoTraverseInterpreter.interpretWholeTable(DoTraverseInterpreter.java:89)\r\n\tat fitlibrary.DoFixture.interpretWholeTable(DoFixture.java:73)\r\n\tat fitlibrary.suite.InFlowPageRunner.run(InFlowPageRunner.java:27)\r\n\tat fitlibrary.DoFixture.interpretTables(DoFixture.java:42)\r\n\tat dbfit.DatabaseTest.interpretTables(DatabaseTest.java:26)\r\n\tat fit.Fixture.doTables(Fixture.java:81)\r\n\tat fit.FitServer.process(FitServer.java:81)\r\n\tat fit.FitServer.run(FitServer.java:56)\r\n\tat fit.FitServer.main(FitServer.java:41)\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If you are using the java version of DBFit and you want to connect to SQL Server you may start to think it can't be done. Fear not! It is possible! I'll summarize the required steps as well as all the error messages I received along the way. Running through these steps will enable you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[184,183],"tags":[186,190,9],"class_list":["post-858","post","type-post","status-publish","format-standard","hentry","category-dbfit","category-test-driven-development-tdd","tag-dbfit","tag-jdbc","tag-sql-server"],"_links":{"self":[{"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/posts\/858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/comments?post=858"}],"version-history":[{"count":11,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/posts\/858\/revisions"}],"predecessor-version":[{"id":881,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/posts\/858\/revisions\/881"}],"wp:attachment":[{"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/media?parent=858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/categories?post=858"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/tags?post=858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}