我正在使用active_delegate在Rails中进行多个连接.这里我使用mysql作为master_database用于某些模型,而postgresql用于其他一些模型.
问题是,当我尝试访问mysql模型时,我收到以下错误!堆栈跟踪显示,它仍然使用postgresql适配器来访问我的mysql模型!
RuntimeError: ERROR C42P01 Mrelation "categories" does not exist P15 F.\src\backend\parser\parse_relation.c L886 RparserOpenTable: SELECT * FROM "categories"
STACKTRACE
===========
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/postgresql_adapter.rb:507:in `execute'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/postgresql_adapter.rb:985:in `select_raw'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/postgresql_adapter.rb:972:in `select'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:81:in `cache_sql'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:661:in `find_by_sql'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1553:in `find_every'
d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:615:in `find'
D:/ROR/Aptana/dedomenon/app/models/category.rb:50:in `get_all_with_exclusive_scope'
D:/ROR/Aptana/dedomenon/app/models/category.rb:50:in `get_all_with_exclusive_scope'
D:/ROR/Aptana/dedomenon/app/controllers/categories_controller.rb:48:in `index'
Run Code Online (Sandbox Code Playgroud)
这是我的database.yml档案
postgre: &postgre
adapter: postgresql
database: codex
host: localhost
username: postgres
password: root
port: 5432
mysql: &mysql
adapter: mysql
database: project
host: localhost
username: root
password: root
port: 3306
development: …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的项目中添加一个数据库/模式/ persistenceUnit,我收到错误:
No unique bean of type [javax.persistence.EntityManagerFactory] is defined: expected single bean but found 2
我谷歌/ api分配,无法找到为什么春天抱怨我的配置.
这是我的applicationContext.xml的一部分
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="transactionManager" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="${show.hibernate.sql}" />
<property name="generateDdl" value="false" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
</bean>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${database.driver}" />
<property name="url" ...
<property name="testOnBorrow" value="true" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="entityManagerFactoryREST" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSourceREST" /> …Run Code Online (Sandbox Code Playgroud) 示例应用程序,具有员工信息并由不同的应用程序(如工资单和pos)访问.我将员工数据放在一个数据库中,工资单数据和pos分别位于不同的数据库中.
我有一个像下面这样的数据库连接类,所以每次我想获得与数据库的连接我就是这么做的$conn = Database::getInstance(db1).
效果很好,但基本上超级慢.使应用程序运行非常慢.关于为什么那样或更好的替代想法的任何提示?
任何帮助将不胜感激
<?php
class Database {
private $db;
static $db_type;
static $_instance;
private function __construct($db){
switch($db) {
case "db1":
try{
$this->db = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USER, DB_PASSWORD);
}
catch(PDOException $e){
print "Error!: " . $e->getMessage() . "<br />";
die();
}
break;
case "db2":
try{
$this->db = new PDO("mysql:host=" . DB_HOST_2 . ";dbname=" . DB_NAME_2, DB_USER_2, DB_PASSWORD_2);
}
catch(PDOException $e){
print "Error!: " . $e->getMessage() . "<br />";
die();
} …Run Code Online (Sandbox Code Playgroud) StackOverflow中有关NHibernate和多个数据库(动态连接)的一些问题,让我相信最好的解决方案是保持SessionFactory(每个数据库)的缓存和缓存到Configuration,以更快地构建SessionFactory.
我想知道这种方法是否正确,主要是:就每个实例的内存消耗和构建时间而言,SessionFactory的"权重"是什么?
更多关于我的方法:
已知第一级和第二级缓存存在于SessionFactory"领域"中,我们可以假设内存消耗可能与打开的ISession量(包括第一级缓存级别)有关.
对于第二级缓存级别,在我的情况下,数据库共享相同的模式并具有一些commom只读表,我可以使用全局缓存实现仅共享所有SessionFactories中的只读表,这对我的项目来说听起来不错.
我对吗 ?这种方法可以带来什么样的性能和内存问题?考虑一个Web应用程序(ASP.NET MVC,而不是Webforms)访问数百个(或几千个)数据库,在每个HTTP REQUEST上找到用户数据库并解决对它的访问(获取,使用和部署ISession).
连接池:连接池怎么样?管理数百或数千个数据库池应该采取什么样的行为?与NHibernate一起使用的一些当前实现可能会有所帮助,或者我需要构建自己的实现?
我有两个数据库,我必须在我的应用程序中使用.我的mongoid.yml中有以下内容:
development:
# Configure available database sessions. (required)
sessions:
# Defines the default session. (required)
default:
# Defines the name of the default database that Mongoid can connect to.
# (required).
database: db_development
username: myusername
password: mypassword
# Provides the hosts the default session can connect to. Must be an array
# of host:port pairs. (required)
hosts:
- myserverip:27017
databases:
secondary:
database: db2_development
username: myusername
password: mypassword
# Provides the hosts the default session can connect …Run Code Online (Sandbox Code Playgroud) querying multiple-databases mongoid ruby-on-rails-3 mongoid3
将应用程序升级到Rails 5后,我收到以下错误,这有点神秘:
...connection_specification.rb:170:in `spec': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
Run Code Online (Sandbox Code Playgroud) 我试图在laravel 5中建立一个多数据库应用程序。我有一个数据库A和另一个数据库B。在数据库A中有我的主要模型。现在,我尝试编写一个迁移文件,该迁移文件在数据库B中创建一个新表。之所以可行,是因为可以在模式构建器中设置与数据库B的连接,如下所示:
Schema::connection('foo')->create('users', function (Blueprint $table) {
$table->increments('id');
});
Run Code Online (Sandbox Code Playgroud)
但是这里的问题是,迁移表仍位于数据库A中。我想在数据库A中为数据库A中的所有表创建一个迁移表,并为数据库B中的所有表创建一个迁移表。在数据库B中。
我正在搜索这样的东西:
Schema::connection('foo')->migrations_table_connection('foo')->create('users', function (Blueprint $table) {
$table->increments('id');
});
Run Code Online (Sandbox Code Playgroud)
有什么办法吗?谢谢
我们正在开发一个将作为托管解决方案提供的应用程序。我对如何在不复制基本代码的情况下使用多个具有相同代码的站点感到惊讶。
例如:网站1:www.example.com和网站2:www.sample.com将在相同的代码上运行,但是具有不同的配置设置和不同的主题...就像我们在wordpress中运行自己的域名一样。
我想知道我该怎么做。
同样在数据库的情况下..最好是我为每个网站创建单独的数据库,或者将具有网站ID的相同数据库用作每个表中的列。
请帮助我。
[说明]它不是域别名。就像...这将是一项服务。在这里,将为不同的客户提供不同主题的相同域名的相同应用程序。类似于博客作者的工作..具有自己的域名,但博客应用程序相同
[技术]专门研究如何使用主机名来确定要使用的配置,我们正在使用PHP和MySQL
build-process multiple-domains multiple-databases application-design
这篇文章描述了如何使用liquibase从maven更新两个数据库: liquibase使用maven和两个数据库 但是,当我在我的pom.xml(包含在下面)中尝试完全相同的配置时,它不起作用.运行'mvn liquibase:update'时出现此错误:
The driver has not been specified either as a parameter or in a properties file.
Run Code Online (Sandbox Code Playgroud)
运行verbose设置为true我得到:
[INFO] Settings----------------------------
[INFO] driver: null
[INFO] url: null
[INFO] username: null
[INFO] password: null
Run Code Online (Sandbox Code Playgroud)
所以看起来配置没有传递给liquibase.如果配置部分是外部执行它可以工作,但这会破坏多次执行的整个想法 - 你会想要为不同的执行使用不同的配置.
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-plugin</artifactId>
<version>1.9.5.0</version>
<executions>
<execution>
<phase>process-resources</phase>
<id>one</id>
<goals>
<goal>update</goal>
</goals>
<configuration>
<changeLogFile>src/main/resources/liquibase/changelog-master.xml</changeLogFile>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://127.0.0.1:3306/${database.development}</url>
<username>wifi_offload_app</username>
<password />
<dropFirst>${liquibase.dropFirst}</dropFirst>
</configuration>
</execution>
<execution>
<phase>process-resources</phase>
<id>two</id>
<goals>
<goal>update</goal>
</goals>
<configuration>
<changeLogFile>src/main/resources/liquibase/changelog-master-sbr.xml</changeLogFile>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://127.0.0.1:3307/${database.development.sbr}</url>
<username>wifi_offload_app</username>
<password />
<dropFirst>${liquibase.dropFirst}</dropFirst>
</configuration>
</execution>
</executions>
<dependencies> …Run Code Online (Sandbox Code Playgroud) 我正在构建一个需要连接 2 个数据库的应用程序。第一个是静态的,另一个是动态的。config/database.php 就像
'mysql' =>
array (
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'blog',
'username' => 'root',
'password' => '',
'unix_socket' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => NULL,
),
'business2' =>
array (
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'blog2',
'username' => 'root',
'password' => '',
'unix_socket' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' …Run Code Online (Sandbox Code Playgroud) database ×2
laravel ×2
php ×2
.net ×1
connection ×1
java ×1
jpa ×1
liquibase ×1
maven ×1
migration ×1
mongoid ×1
mongoid3 ×1
mysql ×1
nhibernate ×1
postgresql ×1
querying ×1
singleton ×1
spring ×1
sql-server ×1
upgrade ×1