PDA

View Full Version : SQLServer Nvarchar unicode test [for Tommy et al]



stanl
09-15-2007, 11:15 AM
I'm doing this on SQLServer Express 2005, but don't think it makes that much difference:

I used a catalog called NCS, the file I want to insert [Russian Unicode] is called unitest.txt, and I create a table named N_MaxText... so I leave it up to you to insure the path/filename and that the table does not already exist. Note: for future posts in this forum... very difficult to provide working code for 'servers'... too many differences

Step 1: using OLEDB, set up connection and create table


adExecuteNoRecords = 128
cConn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=,\SQLEXPRESS;Initial Catalog=NCS"
Set oConn = CreateObject("ADODB.Connection")
oConn.CommandTimeOut=0
oConn.Open(cConn)
cSQL = "CREATE TABLE [dbo].[N_MaxTest] ( [NMaxVar] NVARCHAR(MAX) NOT NULL );"
oConn.Execute cSQL, ,adExecuteNoRecords



now insert file into table using an ADODB Stream Object (and if you have a better way to insert it as unicode w/out a stream let me know)


cFile = "[yourpath]\unitest.txt"
Set oRS=CreateObject("ADODB.Recordset")
Set oS=CreateObject("ADODB.Stream")
oS.Type=2
oS.Open()
oS.LoadFromFile(cFile)
oS.Position=0
oRS.Open "[dbo].[N_MaxTest]",cConn,1,3,2
oRS.Addnew
oRS.collect("NMaxVar")=oS.ReadText()
oRS.Update
oRS.Close
Set oRS=Nothing
oS.Close
Set oS=Nothing
oConn.Close
Set oConn=Nothing


and there you have it, your have inserted a paragraph of Pushkin poetry into a Unicode field.

So, the test.... hmmmm:think: ... you give me code I can use to extract that field, and place it into Excel as both russian and english [via Google's weak Beta translation... that code in the workbook I posted in the previous thread that got us here]. I am re-posting the pushkin unicode... just unzip.

Stan

malik641
09-16-2007, 07:42 AM
I'm having trouble connecting to the Server:
http://img115.imageshack.us/img115/5273/sqlserverunicodetestfainv9.th.png (http://img115.imageshack.us/my.php?image=sqlserverunicodetestfainv9.png)

:dunno

stanl
09-16-2007, 08:52 AM
That would be the major issue which distinguishing testing server code versus local code. I can post what works for me, but others have to ensure that they are connecting to a valid catalog on their own server, and as I said modify any file/paths to their own configuration. Please post your connection string, it's a lot easier to work with than an error message. Stan

malik641
09-16-2007, 09:11 AM
At first, I tried it the way it was. Then I tried adding my name to the "\SQLExpress" since that's how it's stated in my object explorer in SQL Server Management Studio express:
cConn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;Data Source=,JOSEPH\SQLEXPRESS;Initial Catalog=NCS"
What is a catalog? What does it do?

stanl
09-16-2007, 10:36 AM
What is a catalog? What does it do?

A catalog is similar to a database. See my remarks on my post under your regex thread.