當使用OLE DB方式與MS SQL Server連接時,如果數據庫的代碼頁與本地的不同,當進行查詢時字符的返回值就會變成 ? 或是亂碼, 微軟的網站上說這是一個BUG, 並且描述如下:
When you try to retrieve character data from a column with different collation than the clIEnt code page in Microsoft SQL OLE DB Provider (SQLOLEDB), you may receive question marks (??) instead of correct data when all the following conditions are true:
?A connection is made against a Microsoft SQL Server 2000 database.
?SSPROP_IN99v_AUTOTRANSLATE is set to TRUE. SSPROP_IN99v_AUTOTRANSLATE is part of the provider-specific DBPROPSET_SQLSERVERDBIN99v property set.
?A column is bound to an OLEDB DBTYPE_WCHAR data type in the bindings structure.
我的解決方法是關掉 自動字符轉換. 例子如下:(PowerBuilder 中)
SQLCA.DBMS = 'OLE DB'
SQLCA.LogID = 'sa'
SQLCA.LogPass = ''
SQLCA.DBParm = “PROVIDER='SQLOLEDB', DataSource='my-server', CommitOnDisconnect='no', ProviderString='Database=mydb, AutoTranslate=no'”