Blazor Server-side and Firebird Encoding issues - c#

I am retrieving data from a Firebird database and I'm having trouble to get things to work properly.
I've set the database encoding to None and update some values with accents in my DB editor (Flamerobin or other) and store this string:
1_éöüäà
Then I load the data in my Blazor app using default Firebird client and Dapper. If I use a connection string with Charset=None encoding, the loaded string now is
1_�����
Ok so let's change the charset to Charset=ISO8859_1 and relaunch the application. I now get:
1_éöüäà
GREAT - not all is lost, it seems it is stored in DB with ISO8859_1 encoding...
So now, let's edit the value in the Blazor app and store it in the DB still with Dapper and ISO8859_1 charset. I use the SAME connection string for loading and storing data - here is what I actually save (I copy-pasted Dappers' query parameters here):
3_éöüäà
When I check what I have in my DB now (Flamerobin) I get the following strings:
3_éöüäÃ
Ok so the encoding was changed somewhere... After I reload the data in my App, I get the SAME result as above - so encoding was somehow messed up while saving and reloading from DB, using the SAME encoding?! How could that be?!
So well, why not try using Charset=None again to load the data in the app? Guess what, the result is now
3_éöüäà (in App) and 3_éöüäà(in DB)
What? Why would I see the string CORRECTLY by setting Charset=NONE in the connection string but, as it was saved with Charset=ISO8859_1 from the App?
Note that on a WINFORMS app, the exact same manip works the same whether I load/save the data with Charset=None OR Charset=ISO8859_1... Result is alwas as desired : 1_éöüäà.
EDIT: I see the SAME result on my Blazor page AND in the VS debugger console everywhere. I therefore doubt that would be a rendering issue on the browser side - it really is on the .Net / server side that things are happening!

Related

deployed vs local: stored data are unexpected in the deployed app vs local app using mysql

I'm developing a web app and trying to store some input data from a post request using asp.net core 3.1.
at first I should say that I'm using non-English language for inputs.
In local state everything goes fine, however when I publish it and try to store data in MySQL database, values are unexpected(in form of some question marks). the first thing came to my mind was maybe I used an inappropriate charset and encoding, so I change the encoding to the closest thing that I have in my local. didn't work.
I even analyzed the HTTP request and there were no problems.
then I tried to insert directly in phpMyAdmin with insert method. worked fine.
local encoding: utf8mb4_0900_ai_ci
remote encoding: utf8mb4_unicode_ci
any help would be appreciated.
The connection parameters determine the character set of the bytes in the client. To correctly store and retrieve data you must know the charset and announce it when connecting.
While transferring data between the client and server, MySQL will covert from that charset to the charset defined for the columns you are storing into / fetching from.
It sounds like you established the charset correctly for one client and incorrectly for the other.
If you can provide the hex of the characters while in the client, I can further explain.
utf8mb4_0900_ai_ci and utf8mb4_unicode_ci are different Collations for the same character set (encoding) utf8mb4. The characters will go between client and server without any transcoding. However, comparisons may cause trouble due to the different collations.

Gibberish data using npgsql from windows using utf8.en_us encode

I developed a .net program to retrieve data through an api and import the data into postgresql database with utf8 encode hosted on AWS RDS.
The problem is that I developed the code on a windows machine with gb2312(active page code: 936) but I deployed the program on a windows server with utf8.en_us(active page code:437) on AWS. The application running on my machine can correctly store Chinese characters into database and displays well. But it turns out to import Gibberish data into database when running on server.
I tried to do a conversion directly on string within the code, like this:
private string Utf8y(string a)
{
return Encoding.UTF8.GetString(Encoding.Default.GetBytes(a));
}
But it's in vain.
Any idea or solution on this?
Thank you!
Finally find out a solution:
Go to control panel -> language, time, location blabla, change your non-unicode encoding to Chinese(Simplified).
Should work with other languages too.

Part of my project started using incorrect connection string - how do I fix that?

I have one solution with one project in it. This project is an asp.net mvc web application with xsockets.net websocket server (everything merged inside single project).
Everything was working for a few months, until today. Today I decided to update entity framework and xsockets.net. There were few errors on the way, but I solved almost all of them... almost.
Well, the part of my project that runs websocket server is not using correct connection string. I mean, I can login to my web application, and move around it (so asp.net mvc is using correct connection string), but my websocket server (which is using the same database) cannot gather any data from database, since it's throwing incorrect connection string exception.
And since everything is in the single project, with single web.config file, I don't know what to do next. I don't believe that this is websocket related error, maybe entity framework update has changed something? Anyways, is there any way to explicitly use connection string inside of a class? What else I can do to fix that?
When Entity Framework connects to create the entity objects it also establishes the connection string to that database. This usually isn't a problem since that project is referenced by another program that is overriding the server connection string with their own app config (or web config).
Typically in code when connecting to an instance of Sql Server, you write your code:
using ( MyServer context = new MyServer(myconfig.ConnectionStrings["MyServerName"]))
{
}
If you exclude providing he connection string when creating the instance of your context, you risk catching the default value created when you updated entity framework. So this probably answers both your questions: the why is it changed your connection string. The explicit use is the code example above.

Why is entity framework giving this error on web server?

I'm trying to use Entity Framework to add records to a database from a webform input that go into a database on sqlserver.
Everything works fine locally.
I used webmatrix to publish my site to my remote server, the website and my local version of the database is successfully recreated on the remote server with all the data.
However when it comes time to add records to the database, it gives an error on the remote server which i managed to trace to the ctx.Students.Add line.
using (var ctx = new HDPS_SchoolDataEntities())
{
SchoolDataModel.Student temp = new SchoolDataModel.Student();
temp.Name = this.FirstName;
temp.Surname = this.Surname;
temp.Parents = this.Parents;
ctx.Students.Add(temp);
ctx.SaveChanges();
}
I can't find any difference between my local version that works and the one on the remote server that doesn't work. The web.config seems to be configured as expected and all the necessary dll's are in my bin folder but it just won't work on the remote server... any ideas what could be wrong?
Oops forgot the error message!
edit
after Installing .net 4.5 and changing the connection mode from windows authentication to SQL authentication the error now becomes:
Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.
Everything should be the same on the webserver as the entire website is being copied across but it works fine locally so not sure what the problem is...
OKay I solved the issue with the help of this webpage
http://blog.oneunicorn.com/2012/02/26/dont-use-code-first-by-mistake/
In short It seems webmatrix was does not include the metadata part of the connection string on upload to the server thus the EDMX file containing all the information mapping the classes to the database tables was not being referenced causing any queries to the framework to fail.
Once i pasted the original connection string generated by the Entity Framework wizard onto the server everything worked fine.
Based on the error given in your comment, it sounds like you are failing to connect to the database. Check your connection string, username and password. If those are correct, make sure your database settings allows connections from your server ip address.
OKay I solved the issue with the help of this webpage
http://blog.oneunicorn.com/2012/02/26/dont-use-code-first-by-mistake/
It seems webmatrix was does not include the metadata part of the connection string on upload to the server thus the EDMX file containing all the information mapping the classes to the database tables was not being referenced causing any queries to the framework to fail.
Once i pasted the original connection string generated by the Entity Framework wizard onto the server everything worked fine.

Problems displaying/inserting special characters, MySql ASP.NET

I've got problems with special characters being inserted and displayed properly. It's an ASP.NET 3.5 application (C#) and the database is MySql.
If I try to insert a special character into the database using a console app I get an error back saying 'Incorrect string value: '\x81 etc'. If I try to display them it displays for example ü instead of ü.
It works on my local machine, and the only difference I can find (and most likely the root of the problem) is that collation_server is set to latin1_swedish_ci on my machine, utf8_general_ci on the dev server, and character_set_server is latin1 on my machine, utf8 on the dev server. (Everything else is set to utf8 on both machines.)
I thought utf8 was the best thing to use, so now I'm not sure if I should change the dev server to be the same as my local machine which works, i.e. use latin, or change my local machine to be the same as the dev server and look for another solution to the problem? Any thoughts?
Thanks,
Annelie
Set your connection string as follows:
"server=<server>;port=<port>;database=<db>;uid=<uid>;pwd=<password>;charset=utf8;"
Example:
"server=localhost;port=3306;database=mydb;uid=root;pwd=root;charset=utf8;"
(add charset=utf8 to it)

Categories

Resources