Home > database >  C mysql ado connection problem
C mysql ado connection problem

Time:09-27

User DSN system DSN have configuration, test ok, but the connection is still an error [Microsoft] [ODBC driver manager] did not find the data source name and did not specify a default driver, can you tell me what is problem?

Splicing code:
 TCHAR sqlUrl [64]={0}, * lpMask=NULL; 
Long defPort (3306);//the default port 3306
If (lpMask=ado_control: : GetMask (sqlUrl))//have port Settings
{
* lpMask=0;
DefPort=__string_to_long__ (lpMask + 1);
}
Wsprintf (sqlConn, TEXT (" the Provider=MSDASQL. 1;" )
The TEXT (" Persist Security Info=False;" )
The TEXT (" Extended Properties=Driver=MySQL 5.3 Unicode ODBC Driver." )
The TEXT (" SERVER=% s. UID=% s. The PWD=% s." )
The TEXT (" DATABASE=% s. PORT=% d "),
SqlUrl pInfo - & gt; DbUser pInfo - & gt; DbPasswd pInfo - & gt; DbName, defPort);


Connection:
 BOOL rtCode (FALSE); 
Ado_control: : GetSqlConn (pInfo lpSql);
CoInitialize (NULL);
Try
{
//if it is Windows 7, need to be able to login as an administrator, or a "unspecified error"
_ConnectionPtr pConn;
PConn. CreateInstance (__uuidof (Connection));
PConn - & gt; PutConnectionTimeout (15 l);
PConn - & gt; Open (lpSql, L ", "L", "adOpenUnspecified);
RtCode=TRUE;
}
The catch (_com_error & amp; Er)
{
Char strComError [255]={0};
Sprintf (strComError, "wrong number: 08 lx \ n % error source: % s \ n error description: % s",
Er (LPCSTR). The Error (),//wrong number
(LPCSTR) er. Source (),//error Source
Er (LPCSTR). The Description ());//error description

OutputDebugStringA (strComError);

Lstrcpyn (lpSql, er. ErrorMessage (), 128);
}
The catch (... )
{
Lstrcpy (lpSql, TEXT (" unknown error occurred!" ));
}
CoUninitialize ();

CodePudding user response:

system DSN configuration all there is
  • Related