问题描述
我有一个使用SQLOLEDB连接到SQL数据库的现有应用程序。由于SQLOLEDB已被弃用,我正在寻找一种更容易的替代方案来转移到某些不被弃用的东西。一种选择显然是转移到ODBC但是
需要进行大量更改。相反,我正在考虑使用MADASQL,因为客户端代码已经是OLEDB,可能我只需要在连接部分进行更改。
I have an existing application which uses SQLOLEDB to connect to SQL database. Since SQLOLEDB is deprecated, I am looking for an easier alternative to move to some thing which is not deprecated. One option is to obviously move to ODBC but that would require lot of change. Instead, I was thinking about using MADASQL since the client code is already OLEDB, and probably I would need to make change only in the connection part.
但我没有找到任何文档或示例代码将帮助我。我找到的所有示例代码都是用于ADO应用程序的转换,其中只有连接字符串需要更改。我找不到从SQLOLEDB
到MSDASQL的任何内容。
这就是我现有的代码所做的事。
步骤1
CoCreateInstance(CLSID_SQLOLEDB,NULL,CLSCTX_INPROC_SERVER,IID_IDBInitialize,(void **)ppIDBInitialize);
步骤2
  InitProperties [0] .dwPropertyID = DBPROP_INIT_PROMPT;
  InitProperties [0] .vValue.vt = VT_I2;
  InitProperties [0] .vValue.iVal = DBPROMPT_NOPROMPT;
  同样设置以下属性
  DBPROP_INIT_DATASOURCE,其值为"sqlservername \instancename"
  DBPROP_INIT_CATALOG 值为"databasename"的数字为
  DBPROP_AUTH_INTEGRATED,其值为空字符串
  DBPROP_INIT_TIMEOUT,含30周
  pIDBInitialize-> QueryInterface(IID_IDBProperties,(void **)& pIDBProperties);
  hr = pIDBProperties-> SetProperties(1,& rgInitPropSet);
步骤3
  UINT hr =(* ppIDBInitialize) - > Initialize();
$
- 我将CLSID更改为"CLSID_MSDASQL",并且第一次调用成功。
- 根据https://docs.microsoft.com/en-us/sql/ado/guide/appendixes/microsoft-ole-db-provider-for-odbc上的文档,我有尝试了以下属性的几种替代方法。
- 除了这5个属性外,我还尝试添加值为"MSDASQL"的DBPROP_PROVIDERFILENAME或DBPROP_PROVIDERFRIENDLYNAME。但是SetProperties因DB_S_ERRORSOCCURRED而失败,并且Initialize调用失败并显示错误"[Microsoft] [ODBC驱动程序管理器]数据源
名称未找到且未指定默认驱动程序"
$
- 我也尝试过添加值为"SQL Server"或"MSDASQL"的KAGPROP_DRIVERNAME,值为"MSDASQL"或"Provider = MSDASQL"或"Provider = MSDASQL"的DBPROP_INIT_PROVIDERSTRING等。
如何更改现有代码以使用MSDASQL?或者我的方法本身是错误的,除了转移到ODBC之外别无选择?
But I am not finding any documentation or sample code which will help me in this. All the sample code that I found was for conversion of ADO application where only the connection string needs change. I did not find anything for moving from SQLOLEDB to MSDASQL.
This is what my existing code does.
Step 1
CoCreateInstance(CLSID_SQLOLEDB,NULL,CLSCTX_INPROC_SERVER,IID_IDBInitialize,(void**)ppIDBInitialize);
Step 2
InitProperties[0].dwPropertyID = DBPROP_INIT_PROMPT;
InitProperties[0].vValue.vt = VT_I2;
InitProperties[0].vValue.iVal = DBPROMPT_NOPROMPT;
Similarly following properties are set
DBPROP_INIT_DATASOURCE with value "sqlservername\instancename"
DBPROP_INIT_CATALOG with value "databasename"
DBPROP_AUTH_INTEGRATED with value empty string
DBPROP_INIT_TIMEOUT with 30
pIDBInitialize->QueryInterface(IID_IDBProperties, (void**)&pIDBProperties);
hr = pIDBProperties->SetProperties(1, &rgInitPropSet);
Step 3
UINT hr = (*ppIDBInitialize)->Initialize();
- I changed the CLSID to "CLSID_MSDASQL", and first call is successful.
- Based on the documentation at https://docs.microsoft.com/en-us/sql/ado/guide/appendixes/microsoft-ole-db-provider-for-odbc , I have tried several alternatives of below properties.
- Along with these 5 properties, I tried adding DBPROP_PROVIDERFILENAME or DBPROP_PROVIDERFRIENDLYNAME with value "MSDASQL". But SetProperties fails with DB_S_ERRORSOCCURRED, and Initialize call fails with error "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"
- I have also tried adding KAGPROP_DRIVERNAME with value "SQL Server" or "MSDASQL", DBPROP_INIT_PROVIDERSTRING with value "MSDASQL" or "Provider=MSDASQL" or "Provider=MSDASQL;" etc.
How can I change the existing code to make use of MSDASQL? Or my approach itself is wrong, and there is no alternative to moving to ODBC?
谢谢,
-Nilesh。
推荐答案
你需要做的是指定驱动程序在某个地方(除非你想玩DSN,我说你没有)。这很可能是一个特定于Kagera / MSDASQL的初始化属性。 KAGPROP_SERVERNAME听起来不错。
但值应为SQL Server ODBC Driver 13.1,因为这是您应该使用的ODBC驱动程序。你调用SQL Server的那个就像SQLOLEDB一样古老。
What you need to do is to specify the driver somewhere (unless you want to play with DSNs, and I'm saying that you don't). That is likely to be a initialisation property which is specific to Kagera/MSDASQL. KAGPROP_SERVERNAME sounds like a good bet. but the value should be SQL Server ODBC Driver 13.1, because this is the ODBC driver you should use. The one you call SQL Server is just as antique as SQLOLEDB.
但是使用DBPROP_INIT_PROVIDERSTRING可能更容易。
But it may be easier to use DBPROP_INIT_PROVIDERSTRING.
这篇关于将现有的OLEDB应用程序从SQLOLEDB更改为使用MSDASQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!