Azure website IIS not encoding utf8 - mysql

My website is in Azure and the Database is MySQL, ASP.NET 4.0
When I run on localhost (Connected to production DB), I can read-write to the DB in utf8.
When I run on Azure (aka, production) I can only read DB in utf8 but when trying to write it inserts '???? ???? ????'.
So, If it's the same Database and same code, the difference must be IIS, no?
Can anyone assist me how to define it to work?
(btw, the MySQL connection-string has 'charset=utf8')
update:
the web.config file has:
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />

A Ha!
It was Azure!
I needed to go to the Azure Portal and change the connection string there as it ignores my web.config connection string and uses that one instead.
By the way, adding the charset=utf8 there did the trick.
I hope someone will find it useful.

Related

What's changing the "localhost" in ASP.NET Core connection string?

My asp.net core website talks to mysql using MySql.Data.MySqlClient.The connection string is set in appsettings.json as:
"ConnectionStrings": {
"DefaultMySqlConnection": "Server=localhost;Database=mydb;Uid=someuser;Pwd=somepassword;"
}
In mysql server, which is deployed on the same ubuntu server with the app, I've added the user 'someuser'#'localhost'and granted the permissions accordingly.
I'm sharing this server machine with a friend, who already has his own website deployed, including a db on the same mysql server. I didn't think this could cause a problem, until I see in the log that my website is trying to authenticate on the mysql server as user 'someuser'#'myfriendssite.com', instead of the expected 'someuser'#'localhost'.
So at what stage could the localhost in connection string be replaced to myfriendssite.com? The only place I know and checked is the /etc/hosts file, which looks pretty standard:
And, maybe this will be obvious if the above question is answered: how does one avoid this?
Thank you!
Turns out it's using the /etc/hostname, as explained in here.

Does MySQL Connector/J read ~/.my.cnf?

I have a Java application that uses MySQL with the Connector/J MySQL connector. I would like to specify the default client charset in the $HOME/.my.cnf file of the application user, so that it does not affect other applications on the same server.
To test whether Connector/J uses $HOME/.my.cnf, I created the file with the following content:
[client]
socket=/tmp/inexisting-mysql.sock
I expected that the Java application fails to connect to the database, because the /tmp/inexisting-mysql.sock does not exist. However, the application can still connect to the database successfully. It looks like Connector/J is not reading this configuration file at all.
How can I make Connector/J read the $HOME/.my.cnf? Or how can I specify a [client] section option for just my Java application, but not for other applications that use the same database?
Regards, Benedikt
To set the default client charset for a connection you can give that as a parameter to the connection itself:
jdbc:mysql://localhost:3306/sakila?useUnicode=true&characterEncoding=UTF-8
I don't think there is a way to make Connector/J read your $HOME/.my.cnf out of the box. You could read that file in the java application and set the url parameter accordingly though.

CloverETL mySQL Database SSL secure connection & Parameters

I am trying to make the connection to a remote mysql database in CloverETL Designer (Community Version)
Documentation with examples on this subject seem fragmented so I have tried to piece the bits together but I'm not use if they are correct. I would be grateful for any suggestions or further clarification on this subject.
Here is what I have so far:
The SSL Certificate
As an alternative VPN connection the server guys passed me the raw CA certificate, which I saved as a .crt file in the conn folder of the CloverETL workspace.
CloverETL Connections
I created a new DB connection and tested it was working without SSL
In the graph window I created a simple graph
Switching to Source View I added the parameter attribute to the connection code like this:
<Connection database="MYSQL" dbURL="jdbc:mysql://hostname/database_name" id="JDBC0" jdbcSpecific="MYSQL" name="CPM" parameters="ssl=${WORKSPACE}/conn/mysql_cpm_cert.crt" password="password" type="JDBC" user="username"/>
Then I tested the connection to the database by creating new metadata from a DB table
The problem is that I don't know if the connect is now secure or not.
Here's the list of resources that I used to piece together the information:
components:bulkloaders:mysql_data_writer [CloverETL wiki]
MySQL :: MySQL 5.0 Reference Manual :: 6.3.6.3 SSL Command Options
Thanks
CPM
Your setup almost certainly does not use ssl. Both links you posted are not usable - first describes bulk loader and second connection via command line client. But what you need is to configure JDBC. So I would use http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html section "Security."
I would set:
useSSL=true
requireSSL=true
You will do that by adding items in table (Custom JDBC properties) on second tab (Advanced) of Connection Wizard. In source it should appear like "jdbc.useSSL=true jdbc.requireSSL=true" not "parameters=".
Then connection should fail, because in your default java key store is missing your certificate. It can be imported via http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/keytool.html section "Importing Certificates"
I hope this helps.

MySql database deployment in cloudfoundry

I've developed an application using JSP, Spring Security, MySql. I deployed it on Cloudfoundry. But just war file and I binded mysql service. But I also have to configure MySQL database that consists of two tables, new user and it all in my own database. While i tested my application on localhost i prepared the database running manual scripts in MySQL command window.
Question: How can I make the same configurations in CloudFoundry? can I the same way run all commands and scripts manually or export the database somehow? if yes, how to do this. And what to write here now instead of localhost?
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/security_filter" />
thank you
Caldecott (vmc tunnel) is the correct way to access your cloudoundry database (for me it works and i am using ruby 1.8): http://docs.cloudfoundry.com/tools/vmc/caldecott.html
If that does not work for you you will have to do something manually (much harder):
Create a sample jsp/servlet application that connects to a mysql database (retrieving connection string, username and password as input from user). Then it will just run the sql statement against the database ( sql statement will be also input from user)
Bundle this application in your war
Now you have to retrieve database connection string/username and password. You can retrieve them from the enviromental variable VCAP_SERVICES. Just log log it in a startup listener (eg ServletContextListener)
Deploy your war and get logs from server (vmc logs ApplicationName). Get connection string, username and password
Logon to your application and use your database application to access the database using the db info you collected in the previous step
Just note that this is very dangerous approach. Just be sure to secure this database application or after the initial import remove it from your war and redeploy the application
As a final note you can check if such a database console application already exists so that you dont have to create your own (for example grails has a nice application for this http://grails.org/plugin/dbconsole. Maybe something exists for jsp/servlets)
Hope it helps if you have no luck with the ruby problem
You would need to create a mysqldump of your database.
Once you have the mysqldump file, you then use caldecott and perform vmc tunnel to your MySQL service. After you have establish a connection with your MySQL service on Cloud Foundry, you then need to use the mysql command to manually import the mysqldump file into your service.
For how to use vmc tunnel, visit the documentation site at: http://docs.cloudfoundry.com/tools/vmc/caldecott.html

EF4.1/MVC3 Database First: How to remove password from connection string

I'm building a website with EF4.1 and MVC3 (C#). Trying to find out what the proper way to remove the password from the connection string is. I've done some searching and can't seem to find anything that tells how to remove the password from the connection string.
I'm actually working on two different sites at the moment. One is hosted on GoDaddy and is using their SQL Server db. The other is hosted here at work and will be using SQL Server 2005.
Lastly, is it possible to do the database first code generation with a MySQL database? I'm personally more comfortable with MySQL and prefer it to SQL Server, but have had issues getting this to work.
If you should need any additional information please let me know.
You should probably encrypt your web.config connection strings before deploying it to the server.
AFAIK, if you connect to your server using SQL Server Authentication, the connection string needs the username and password. If your app and db servers had domain trust, you can use integrated mode / windows authentication / identity impersonate to have a password-less connection string. But most service providers don't let you do this -- they use SQL Server Authentication to keep customers out of their domain.
Either way, there is more sensitive information in the connection string than just the password. You should encrypt the whole <connectionStrings> node.