I'm moving my application to AWS ElasticBeanStalk and after spending countless hours trying to get my database connection working, I've repetitively failed.
First attempt,
I currently have an existing RDS database in use which I would like to continue use. I tried to connect to it with a plain old jdbc connection as followed.
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://masdfwe.czwweehqejmbr.us-east-1.rds.amazonaws.com:3306/project</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">xxxxx</property>
But found the following exception in the log.
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://masdfwe.czwweehqejmbr.us-east-1.rds.amazonaws.com:3306/project
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:187)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:192)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:278)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
... 125 more
The mysql driver is deff in the lib directory, so I'm not sure why I'm seeing this exception.
Do I need to create a JNDI connection? If so, how do I go about altering the configuration files in tomcat7 on ElasticBeanStalk? Am I suppose to ssh into the ec2 instance, or do I do it into the ElasticBeanStalk instance?
Would I use something like this in my hibernate.cfg.xml file?
<property name="hibernate.connection.datasource">java:comp/env/jdbc/project</property>
web.xml
<resource-ref>
<description>MyDatabase Description</description>
<res-ref-name>jdbc/project</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
I'm just not sure where or what I'm suppose to be configuring. Any help would be appreciated, I'm very confused.
Thanks in advance.
You shouldn't have to much about with JNDI to get your RDS connection to work. From your description, I'm also a bit puzzled as to what's not working for you. I've set up my JDBC/RDS connections with no problems, although I've used Spring to access the database, so details are handled by Spring's data sources.
Just an idea: You do have a
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
to load your JDBC driver in your code?
Good luck!
Your assumption is right. With Hibernate you should be able to use your configuration as is. No need to instantiate driver by name, it applies to Java code without Hibernate.
Your configuration settings look right.
Could it be that the jar with MySQL connector somehow got damaged? Is there anything else in stacktrace?
I had a similar sounding problem with RDS and MySQL. I tried copying the driver's jar file and manipulating the classpath but none of that seemed necessary nor did it help. Eventually, I changed the code where my DataSource gets initialized to pass in my connection string rather than each property individually (e.g., ds.setUser( xxx )). This resolved my issue.
So in the end, my properties file contains these properties:
app.jdbc.driverClassName=com.mysql.jdbc.Driver
app.jdbc.url=jdbc\:mysql\://xyz.rds.amazonaws.com:3306/schema?user=username&password=mypassword
And my data source config:
ComboPooledDataSource ds = new ComboPooledDataSource();
ds.setDriverClass( jdbcDriverClassName );
ds.setJdbcUrl( jdbcUrl );
// other ds configuration parameters follow
With this change, I was able to overcome the "driver" exception and connect to the RDS database as expected.
Related
I created my scaled application on Openshift server with following command:
rhc app create MyApp jbossews-2.0 -s
Then add Mysql:
rhc cartridge add mysql-5.5 -a MyApp
My application using Struts2, Spring & Hibernate. I configured the datasource as follow:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/MysqlDS"/>
</bean>
The JNDI "MysqlDS" is defined in .openshift\config\context.xml with the connection url:
url="jdbc:mysql://5344d4de4382ec43c9000090-myapp.rhcloud.com:37941/mydb"
The problem is my scale app can not establish the connection to Mysql with an error:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect
3 times. Giving up.)
I'm sure the username & password to access the database is correct. It seem MySQL on Openshift server doesn't open its port. When I tried to use an external database on freemysqlhosting.net (with open host & port) the application run well. But I just want to use MySQL db on Openshift. Anyone who have experience on this please give me some suggestion. Thanks
Make sure that you restarted your application after adding the mysql cartridge, sometimes the environment variables don't show up correctly until you restart. Also try to ssh to your gear and see if you can use the "mysql" command to connect to your mysql database directly.
If you left the .openshift/config/context.xml unchanged, the JNDI name fore the MySQL datasource is actually jdbc/MySQLDS and not jdbc/MysqlDS.
This was changed some time ago.
The documentation here http://openshift.github.io/documentation/oo_cartridge_guide.html#tomcat-cartridge-integrations is unfortunately not correct.
I successfully completed the DataNucleus Tutorial for JDO using RDBMS with a local MySQL instance on my Ubuntu 13.10 machine.
While attempting to get the same working on a Google CloudSQL instance, I ran into some problems.
To make the switch, I replaced the following:
<property name="javax.jdo.option.ConnectionURL" value="jdbc:mysql://127.0.0.1/nucleus?useServerPrepStmts=false"/>
<property name="javax.jdo.option.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
... with the following:
<property name="javax.jdo.option.ConnectionURL" value="jdbc:google:mysql://<my-project>:nucleus/nucleus?useServerPrepStmts=false"/>
<property name="javax.jdo.option.ConnectionDriverName" value="com.mysql.jdbc.GoogleDriver"/>
I setup the local MySQL and the CloudSQL instances to have the same credentials, so the javax.jdo.option.ConnectionUserName and javax.jdo.option.ConnectionPassword did not need to be changed.
Under the Google Cloud Console Cloud SQL my-project:nucleus MySQL instance, I created a static IP and also whitelisted my development machine's IP address. I verified that I was able to connect natively to it via 'mysql -u root -p -h '.
When I try to run 'mvn datanucleus:schema-create', I get this:
[DEBUG] Exit code: 1
[DEBUG] --------------------
[DEBUG] Standard output from the DataNucleus tool org.datanucleus.store.schema.SchemaTool :
[DEBUG] --------------------
[INFO] DataNucleus SchemaTool : Creation of the schema
An error was encountered creating a PersistenceManagerFactory : Error creating transactional connection factory - please consult the log for more information.
If I replace the connection settings with the following then it works the same as with the local MySQL instance:
<property name="javax.jdo.option.ConnectionURL" value="jdbc:mysql://<Cloud SQL IP>/nucleus?useServerPrepStmts=false"/>
<property name="javax.jdo.option.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
So, I've worked around the problem, but why didn't this work with the GoogleDriver? I don't know anything about the black magic that's going on inside that driver, but I'm curious if there was a way to make that work, and whether there's a reason I should use the GoogleDriver at all.
Now that you can use the stock MySQL driver with Cloud SQL, you should use that instead of the older GoogleDriver.
See http://googlecloudplatform.blogspot.com/2013/10/google-cloud-sql-now-accessible-from-any-application-anywhere.html
Hope this helps,
Rob
The special Google JDBC driver is for use from Google App Engine applications only. When using it, the CloudSQL instance does not require a static public IP address, which is a billable feature of CloudSQL.
This all becomes obvious after reading the Google CloudSQL docs here and here.
I am trying to create a web app using ASP.Net MVC3, Entity Framework and MySQL.
I have added the following code to my Web.Config file.
<connectionStrings>
<add name="ContactContext" connectionString="server=localhost;database=contacts;uid=root;pwd=password;" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
I also have created "Person" Model , "ContactContext" in the project "Contact_Me". When I try to create a "ContactController" including Person Model and Contact context, it gives me the following error
"Unable to retrieve metadata for "Connect_Me.Models.Persons". The
provider did not return a ProviderManifestToken string"
MYSQ & MVC3 SQL connection error \ ProviderManifestToken but I am using MySQL, this is the closest question to mine. But the answer didn't solve my problem.
Thanks in advance
I know this may be very basic for a couple of you guys, but this exception is also thrown in cases where EF is unable to locate a Connection String to use.
If you-re working in a multi-layered application, make sure the connection String is added to your client application, instead of the class library that contains you data access code.
Just my 2 cents.
I got this error when my sql server was actually down. So, please be sure that your sql server is up and running.
You can also get this error if you upgrade Nuget references in an EntityFramework project that uses MySql.Data.Entity (latest version is 6.10.X) and MySql.Data (latest version is 8.0.X). Those version numbers should match. You should use the MySql.Data.EntityFramework package with MySql.Data version 8.0 and after, and the MySql.Data.Entity package with versions 6.10 and before.
There are a lot more details in this blog post: https://davidsekar.com/asp-net/mysql-error-the-provider-did-not-return-a-providermanifesttoken
The problem was with the MySQL connector/Net.
I previously used MySQL connector/Net 6.3.5 and after I uninstalled it and installed MySQL connector/Net 6.5.4 the issue was fixed. You can find latest connectors at http://www.mysql.com/products/connector/
Sometimes this issue arises because of sslmode as well, For me the solution was to add sslmode=None to connection string
I had to make a small change to my connection string from
<add name="Connection" connectionString="Server=SOMEHOST;Database=DB;Uid=USR1;Pwd=PASS1;" providerName="MySql.Data.MySqlClient" />
to
<add name="Connection" connectionString="Server=SOMEHOST;Database=DB;Uid=USR1;Pwd=PASS1;sslmode=None;" providerName="MySql.Data.MySqlClient" />
May be the error is in your connection string. Have you tried to connect to your DB instance using the above log in. try changing the connection string
connectionString="Data Source=.;Initial Catalog=contacts;Integrated Security=True uid=root;pwd=password;" providerName="MySql.Data.MySqlClient"/>
use above if you are using sql server, else if you are using sql express use below one
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=contacts;Integrated Security=True uid=root;pwd=password;" providerName="MySql.Data.MySqlClient"/>
Even though this is answered, but I have experienced the same problem and my in case it was in the connection string; I had the part "Integrated Security" when I really shouldn't have used it; I was relying on the database authentication.
I removed the "Integrated Security=True" part and it worked perfectly :)
Restarting the computer worked for me.
While this message was showing, I did not find any differences between my computer [Windows 10] and the test server where the the application was deployed with the same configuration and was working correctly there and using the same database. It means the issue was probably not connected to the database running on the test server.
Worth mentioning is there were some Windows updates pending while restarting.
I'm in SQLSERVER (2008 R2 EXPRESS) administrators list. I'm in administrator role on my machine. And I can manually connect to SQLSERVER (via Management Tools) using ServerName (in my case it's S-PROG-T\SQLEXPRESS). During installation I decided to use only Windows Authentication mode. I can't connect to SS.
Error message is: Login failed for user S-PROG-T\admin. Cannot open database 'ProjectDB' requested by the login.
I'm using the following configuration for NHibernate:
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="dialect">
NHibernate.Dialect.MsSql2008Dialect
</property>
<property name="connection.driver_class">
NHibernate.Driver.Sql2008ClientDriver
</property>
<property name="connection.connection_string">
Data Source=S-PROG-T\SQLEXPRESS;Initial Catalog=ProjectDB;Integrated Security=SSPI
</property>
<property name="show_sql">
true
</property>
<mapping resource="Project.Domain.Model.Entities.Mappings.Vehicle.hbm.xml" assembly="Project.Domain" />
</session-factory>
And I've tried to connect using .\SQLEXPRESS data source. Inbound rules don't restrict SSMS.
What's wrong?
Thanks!
EDIT: Unit tests
Everything (nhibernate configuration, and schema export trial) starts inside my unit test (I don't know if this matters).
[TestFixture]
public class VehicleFixture
{
[Test]
public void TestSchemaExport()
{
new SchemaExport(new Configuration().Configure()).Execute(false, true, false);
}
}
EDIT: Log information
I discovered the next information inside a log (path: %ProgramFiles%\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\Log\):
Error: 18456; State: 38.
Login failed for user ‘S-PROG-T\Admin’.
Reason: Failed to open the explicitly specified database.
According to the article: http://sql-articles.com/articles/troubleshooting/troubleshooting-login-failed-error-18456/ database doesn’t exist or login doesn’t have access to the database.
I'm totally confused. Should I have created the database (manually) before I tried to export schema (sorry if the question is silly)?
EDIT: Using Mixed Authentication mode
I've set Mixed mode Authentication and created new login with serveradmin & sysadmin roles. But still the error message is the same, except for user name. Again I can manually do the same thing (connect and create db) with the login and its password.
Ok. I misunderstood the whole process. Everything's ok with Authentication and rather with connection strings. I just thought that schema export stands for database automated-creation and then schema export. So I created a DB and successfully exported a schema.
Can you connect with NHibernate if you change database to 'master'?
Is ProjectDB database user S-PROG-T\admin mapped to server login that you use to connect using management tools?
Can you connect to database using user/password combination in property name="connection.connection_string" instead of integrated security = SSPI?
EDIT You write that you created new login. But still - login is something used for SERVER authentication. You must have database user in ProjectDB mapped to server login to access the database.
Look at this thread: TSQL to Map User to Database
or read here: http://www.nerdymusings.com/LPMArticle.asp?ID=41
The website will not be using the same identity, therefore will not be an administrator. You can either define a specific identity and set your ApplicationPool (or your own admin account) to use this. Alternatively, use a login/password rather than integrated security.
I have an existing model for a MySQL database. I've added a new table in my database and now I want to update the model.
But when I right-click in the Model browser and select Update Model from Database... I get following message:
An exception of type 'Microsoft.VSDesigner.Data.Local.ConnectionStringConverterServiceException' occurred while attempting to update from the database. The exception message is: ''.
Application works just fine with existing model. I mean, data is successfully fetched when needed and all.
What might cause the problem with updating the model? Is it because of Express edition? How can I resolve the problem?
UPDATE:
<connectionStrings>
<add name="OtherDbDataContext" connectionString="metadata=res://*/DataAccess.EF.OtherDb.csdl|res://*/DataAccess.EF.OtherDb.ssdl|res://*/DataAccess.EF.OtherDb.msl;provider=MySql.Data.MySqlClient;provider connection string="User Id=id;Password=password;Host=localhost;Database=otherdb;Pooling=true;Min Pool Size=0;Max Pool Size=100;Connection Lifetime=0;Persist Security Info=True"" providerName="System.Data.EntityClient" />
<add name="DbDataContext" connectionString="server=localhost;User Id=id;password=password;Persist Security Info=True;database=db" providerName="MySql.Data.MySqlClient" />
<add name="DbDataConnectionString" connectionString="server=localhost;User Id=id;password=password;Persist Security Info=True;database=db" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
Solved this problem by deleting all connectionstrings from config file. After that when you update model it prompts you to add connectionstrings and everything is working normally.
Hope it helps.
I think the problem is that the connector/net for mysql doesn't fully support express versions. Take a look at this post: Mysql - Visual Web Developer - Entity Framework
My problem with this was related to the Event Log full. Deleted event log entries and that solved the problem. Hope it helps someone.
You need to register your provider in machine.config file. This happens when the provider is not properly registered in the machine.config file.
Try updating the lowest config level closest to the .edmx file which is the app.config.
All in all the problem is connection related and not a problem in the designer IDE.
Same issue with Visual Studio 2012 Professional. After removing connection string from App.config, I cannot add new connection in "Update from database" window. MySQL Data source was missing.
Solved by installing MySQL for Visual Studio (for me it was 1.1.3 version). I had the opportunity to create connections to MySQL database. I revert connection string and even with old connection string all was fine.
Hope it helps.