SonarQube可以连接Azure SQL数据库吗?

时间:2014-06-13 10:07:30

标签: ruby-on-rails ruby sonarqube jruby azure-sql-database

我的SonarQube正在Microsoft Azure的VM实例上运行。现在SonarQube的数据库是MySQL,我正在尝试将MySQL更改为Azure SQL数据库,但是SonarQube无法通过ActiveRecord组件中出现的一些错误来连接Azure SQL数据库。我知道SonarQube不正式支持Azure SQL数据库并且下面支持SQL Server,但Azure SQL数据库与SQL Server兼容,因此可以连接Azure SQL数据库。 如果有人知道,请告诉我如何连接Azure SQL数据库。

SonarQube's Support Database

sonar.properties:

sonar.jdbc.username=sonar@<server>
sonar.jdbc.password=<password>
sonar.jdbc.driverClassName=net.sourceforge.jtds.jdbc.Driver
jdbc:jtds:sqlserver://<server>.database.windows.net:1433/<databasename>;ssl=require

错误跟踪:

org.jruby.rack.RackInitializationException: no connection available
    from arjdbc/jdbc/RubyJdbcConnection.java:517:in `set_native_database_types'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/jdbc/connection.rb:61:in `initialize'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/jdbc/adapter.rb:31:in `initialize'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/jdbc/connection_methods.rb:6:in `jdbc_connection'
    from org/jruby/RubyKernel.java:2227:in `send'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:223:in `new_connection'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:245:in `checkout_new_connection'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:188:in `checkout'
    from org/jruby/RubyKernel.java:1519:in `loop'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:184:in `checkout'
    from jar:file:/opt/sonar/web/WEB-INF/lib/jruby-complete-1.7.9.jar!/META-INF/jruby.home/lib/ruby/1.8/monitor.rb:191:in `mon_synchronize'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:183:in `checkout'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:98:in `connection'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:326:in `retrieve_connection'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in `retrieve_connection'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_specification.rb:115:in `connection'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:440:in `initialize'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:401:in `up'
    from /opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:383:in `migrate'
    from /opt/sonar/web/WEB-INF/lib/database_version.rb:62:in `upgrade_and_start'
    from /opt/sonar/web/WEB-INF/lib/database_version.rb:74:in `automatic_setup'
    from /opt/sonar/web/WEB-INF/config/environment.rb:239:in `(root)'
    from org/jruby/RubyKernel.java:1094:in `load'
    from file:/opt/sonar/web/WEB-INF/lib/jruby-rack-1.1.13.2.jar!/jruby/rack/rails/environment2.rb:1:in `(root)'
    from file:/opt/sonar/web/WEB-INF/lib/jruby-rack-1.1.13.2.jar!/jruby/rack/rails/environment2.rb:25:in `load_environment'
    from file:/opt/sonar/web/WEB-INF/lib/jruby-rack-1.1.13.2.jar!/jruby/rack/rails_booter.rb:79:in `load_environment'

    at org.jruby.rack.RackInitializationException.wrap(RackInitializationException.java:29)
    at org.jruby.rack.RackApplicationFactoryDecorator.init(RackApplicationFactoryDecorator.java:98)
    at org.jruby.rack.RackServletContextListener.contextInitialized(RackServletContextListener.java:50)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.jruby.exceptions.RaiseException: (ConnectionNotEstablished) no connection available
    at arjdbc.jdbc.RubyJdbcConnection.set_native_database_types(arjdbc/jdbc/RubyJdbcConnection.java:517)
    at RUBY.initialize(/opt/sonar/web/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/jdbc/connection.rb:61)
    at RUBY.initialize(/opt/sonar/web/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/jdbc/adapter.rb:31)
    at RUBY.jdbc_connection(/opt/sonar/web/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.1.3/lib/arjdbc/jdbc/connection_methods.rb:6)
    at org.jruby.RubyKernel.send(org/jruby/RubyKernel.java:2227)
    at RUBY.new_connection(/opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:223)
    at RUBY.checkout_new_connection(/opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:245)
    at RUBY.checkout(/opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:188)
    at org.jruby.RubyKernel.loop(org/jruby/RubyKernel.java:1519)
    at RUBY.checkout(/opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:184)
    at RUBY.mon_synchronize(jar:file:/opt/sonar/web/WEB-INF/lib/jruby-complete-1.7.9.jar!/META-INF/jruby.home/lib/ruby/1.8/monitor.rb:191)
    at RUBY.checkout(/opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:183)
    at RUBY.connection(/opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:98)
    at RUBY.retrieve_connection(/opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_pool.rb:326)
    at RUBY.retrieve_connection(/opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_specification.rb:123)
    at RUBY.connection(/opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/connection_adapters/abstract/connection_specification.rb:115)
    at RUBY.initialize(/opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:440)
    at RUBY.up(/opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:401)
    at RUBY.migrate(/opt/sonar/web/WEB-INF/gems/gems/activerecord-2.3.15/lib/active_record/migration.rb:383)
    at RUBY.upgrade_and_start(/opt/sonar/web/WEB-INF/lib/database_version.rb:62)
    at RUBY.automatic_setup(/opt/sonar/web/WEB-INF/lib/database_version.rb:74)
    at RUBY.(root)(/opt/sonar/web/WEB-INF/config/environment.rb:239)
    at org.jruby.RubyKernel.load(org/jruby/RubyKernel.java:1094)
    at RUBY.(root)(file:/opt/sonar/web/WEB-INF/lib/jruby-rack-1.1.13.2.jar!/jruby/rack/rails/environment2.rb:1)
    at RUBY.load_environment(file:/opt/sonar/web/WEB-INF/lib/jruby-rack-1.1.13.2.jar!/jruby/rack/rails/environment2.rb:25)
    at RUBY.load_environment(file:/opt/sonar/web/WEB-INF/lib/jruby-rack-1.1.13.2.jar!/jruby/rack/rails_booter.rb:79)

由于

3 个答案:

答案 0 :(得分:3)

我刚刚发现,在这个问题上花了6个非常令人沮丧的时间之后,这是可能的。以下是我遇到的问题以及我为每个问题提出的解决方案:

  1. 无法连接到Azure SQL Server数据库 - 连接只会超时。解决方案是添加&#34 ;; ssl = require&#34;连接URL和-Djsse.enableCBCProtection = false(参见Connecting to Azure SQL DB via JTDS on an Android device)到服务器的java参数(在conf / wrapper.conf中)。这是我的数据库配置:

    sonar.jdbc.username=<username>@SERVER
    sonar.jdbc.password=<password>
    sonar.jdbc.url=jdbc:jtds:sqlserver://SERVER.database.windows.net:1433/DATABASE;ssl=require;SelectMethod=Cursor
    

    我还将extensions / jdbc-driver / mssql中的jTDS驱动程序从1.2.8升级到1.3.1,但这可能没有必要。

  2. SonarQube会创建一些没有聚簇索引的表,Azure SQL Server不支持这些表(请参阅Tables without a clustered index are not supported in this version of SQL Server)。要解决该问题,我需要使用本地SQL Server Express实例在本地安装SonarQube。在执行此操作后,我运行以下DDL以将有问题的表转换为使用聚簇索引:

    CREATE UNIQUE CLUSTERED INDEX Idx_schema_migrations ON dbo.schema_migrations(version);
    CREATE UNIQUE CLUSTERED INDEX Idx_groups_users ON dbo.groups_users(user_id,group_id);
    

    最后,既然数据库是Azure兼容的,在SSMS内部我右键单击数据库,选择Tasks / Deploy Database to SQL Azure,并将其部署到我的Azure服务器。

  3. SonarQube的数据库升级程序不支持SQL Server 2014(您获得了一个&#34;已弃用的功能&#39; DROP INDEX包含两部分名称&#39;不支持这个版本的SQL Server&#34;错误,从4.3升级到4.4)。我不得不做一个全新的安装来解决这个问题,尽管可能要么自己想出必要的升级DML / DDL,要么升级SonarQube的ActiveRecord JDBC MSSQL适配器(希望他们能够做到这一点)在他们的下一个版本中这样做。)

  4. 简单,对吧? :P

答案 1 :(得分:1)

Azure SQL与本地MS SQL Server安装不同。

此处列出了差异:http://msdn.microsoft.com/en-us/library/azure/ff394115.aspx

此外,Sonarqube的文档仅显示MS SQL Server 2008.在撰写本文时,Azure将基于与MS SQL Server 2014类似(不完全相同)的系统。 (他们总是更新他们的系统。)

答案 2 :(得分:1)

对我而言,只有当数据库名称在属性中分离且没有jtds时才有效。

sonar.jdbc.username=<username>@SERVER
sonar.jdbc.password=<password>
sonar.jdbc.url=jdbc:sqlserver://SERVER.database.windows.net:1433;database=DATABASE;ssl=require;SelectMethod=Cursor

Sonar Qube 5.3版

相关问题