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