SQL Server and unicode

S

Stefano Soratroi

Hi all,
I have the following problem: I have a SQL Server 2000
database with a table containing a column of type nvarchar
(255). In this column the data can contain unicode
characters other than latin1, (ex: greek, korean and so
on). I have written a small .net console application for
testing and in the db field I have written the greek
chars "alfa" "beta" and "gamma" with SQL Server
Enterprise Manager. When I query the table with SQL Query
Analizer it shows me the correct characters, but when I
query the table with my console app, the
charachters "alfa" and "beta" are correct but the "gamma"
charachter is shown as a ?. So I've written a vbs script
that queries the db and the result is that the characters
are all correct, so I suspect it is somewthing wrong or
missing in the .net app. My code is shown below:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace ConsoleApplication1
{
class Class1
{
private const string connstr
= "server=myserver; database=mydb; uid=usr; pwd=pwd";
[STAThread]
static void Main(string[] args)
{

SqlConnection cnn = new
SqlConnection(connstr);
cnn.Open();

string sql = "SELECT nome from
tab";
SqlDataAdapter ad = new
SqlDataAdapter(sql,cnn);
DataSet ds = new DataSet();
ad.Fill(ds);
foreach(DataRow r in ds.Tables
[0].Rows)
Console.WriteLine(r
["nome"].ToString());
cnn.Close();
}
}
}

Any help would be appreciated.

Thanks.

Stefano
 
S

Sushil Chordia

I am able to get the gamma char fine. I am using SQL2k and 1.1 Framework.
Here is my code snippet which uses ExecuteScalar. DataSet also give out
similar results.
<code>
sqlconnection1.Open();
SqlCommand sqlcommand1 = sqlconnection1.CreateCommand();
sqlcommand1.Disposed += new EventHandler(SqlCommand_OnDisposed);
sqlcommand1.CommandText = "select N'?'";
String string1 = (String)sqlcommand1.ExecuteScalar(); // "?"
</code>
It could also be that the command prompt you are using is not set to handle
unicode chars.Try comparing the value you get after select with the "?"
string and check the results.
 
S

Sushil Chordia

In the post ? refer to the gamma chars. (this is the same problem as yours :
auto-conversion of unicode chars to ASCII :)
--
HTH,
Sushil Chordia.
This posting is provided "AS IS" with no warranties, and confers no rights.
Sushil Chordia said:
I am able to get the gamma char fine. I am using SQL2k and 1.1 Framework.
Here is my code snippet which uses ExecuteScalar. DataSet also give out
similar results.
<code>
sqlconnection1.Open();
SqlCommand sqlcommand1 = sqlconnection1.CreateCommand();
sqlcommand1.Disposed += new EventHandler(SqlCommand_OnDisposed);
sqlcommand1.CommandText = "select N'?'";
String string1 = (String)sqlcommand1.ExecuteScalar(); // "?"
</code>
It could also be that the command prompt you are using is not set to handle
unicode chars.Try comparing the value you get after select with the "?"
string and check the results.
--
HTH,
Sushil Chordia.
This posting is provided "AS IS" with no warranties, and confers no rights.
Stefano Soratroi said:
Hi all,
I have the following problem: I have a SQL Server 2000
database with a table containing a column of type nvarchar
(255). In this column the data can contain unicode
characters other than latin1, (ex: greek, korean and so
on). I have written a small .net console application for
testing and in the db field I have written the greek
chars "alfa" "beta" and "gamma" with SQL Server
Enterprise Manager. When I query the table with SQL Query
Analizer it shows me the correct characters, but when I
query the table with my console app, the
charachters "alfa" and "beta" are correct but the "gamma"
charachter is shown as a ?. So I've written a vbs script
that queries the db and the result is that the characters
are all correct, so I suspect it is somewthing wrong or
missing in the .net app. My code is shown below:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace ConsoleApplication1
{
class Class1
{
private const string connstr
= "server=myserver; database=mydb; uid=usr; pwd=pwd";
[STAThread]
static void Main(string[] args)
{

SqlConnection cnn = new
SqlConnection(connstr);
cnn.Open();

string sql = "SELECT nome from
tab";
SqlDataAdapter ad = new
SqlDataAdapter(sql,cnn);
DataSet ds = new DataSet();
ad.Fill(ds);
foreach(DataRow r in ds.Tables
[0].Rows)
Console.WriteLine(r
["nome"].ToString());
cnn.Close();
}
}
}

Any help would be appreciated.

Thanks.

Stefano
 
S

Stefano Soratroi

-----Original Message-----
In the post ? refer to the gamma chars. (this is the same problem as yours :
auto-conversion of unicode chars to ASCII :)

Thank you for your reply, I've this suspect so, instead
of print the result string as is I have printed the
unicode character codes and I looked for them in the
windows character map, and the characters are correct
(the gamma also), is the console that shows me the wrong
character!

Thanks a lot.

I've the same problem with a MySQL db but it doesn't work
at all, any char is converted to a ? char, but this seems
to be a MySQL problem, and I'm using the 4.1.7 version
which has unicode support, but this is another story...
--
HTH,
Sushil Chordia.
This posting is provided "AS IS" with no warranties, and confers no rights.
I am able to get the gamma char fine. I am using SQL2k and 1.1 Framework.
Here is my code snippet which uses ExecuteScalar. DataSet also give out
similar results.
<code>
sqlconnection1.Open();
SqlCommand sqlcommand1 = sqlconnection1.CreateCommand ();
sqlcommand1.Disposed += new EventHandler (SqlCommand_OnDisposed);
sqlcommand1.CommandText = "select N'?'";
String string1 = (String)sqlcommand1.ExecuteScalar (); // "?"
</code>
It could also be that the command prompt you are using
is not set to
handle
unicode chars.Try comparing the value you get after select with the "?"
string and check the results.
and confers no
rights.
Hi all,
I have the following problem: I have a SQL Server 2000
database with a table containing a column of type nvarchar
(255). In this column the data can contain unicode
characters other than latin1, (ex: greek, korean and so
on). I have written a small .net console application for
testing and in the db field I have written the greek
chars "alfa" "beta" and "gamma" with SQL Server
Enterprise Manager. When I query the table with SQL Query
Analizer it shows me the correct characters, but when I
query the table with my console app, the
charachters "alfa" and "beta" are correct but the "gamma"
charachter is shown as a ?. So I've written a vbs script
that queries the db and the result is that the characters
are all correct, so I suspect it is somewthing wrong or
missing in the .net app. My code is shown below:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace ConsoleApplication1
{
class Class1
{
private const string connstr
= "server=myserver; database=mydb; uid=usr; pwd=pwd";
[STAThread]
static void Main(string[] args)
{

SqlConnection cnn = new
SqlConnection(connstr);
cnn.Open();

string sql = "SELECT nome from
tab";
SqlDataAdapter ad = new
SqlDataAdapter(sql,cnn);
DataSet ds = new DataSet();
ad.Fill(ds);
foreach(DataRow r in ds.Tables
[0].Rows)
Console.WriteLine(r
["nome"].ToString());
cnn.Close();
}
}
}

Any help would be appreciated.

Thanks.

Stefano


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top