Home > Software engineering >  Insert the data into the database, there is no data
Insert the data into the database, there is no data

Time:09-23

//adoconnARE. H: interface for the CadoconnARE class. 
//
//////////////////////////////////////////////////////////////////////
# import "c: \ Program Files \ Common Files \ System \ ado \ msado15 DLL" no_namespace rename (" EOF ", "adoEOF") rename (" BOF, "" adoBOF")

# if! Defined (AFX_ADOCONNARE_H__A543BEA8_DFBE_48A2_B8D5_E150D9C01566__INCLUDED_)
# define AFX_ADOCONNARE_H__A543BEA8_DFBE_48A2_B8D5_E150D9C01566__INCLUDED_

# if _MSC_VER & gt; 1000
# pragma once
# endif//_MSC_VER & gt; 1000

The class CadoconnARE
{
Public:
CadoconnARE ();
Virtual ~ CadoconnARE ();

//add a pointer to the Connection object:
_ConnectionPtr m_pConnection;
//add a pointer to the object you:
_RecordsetPtr m_pRecordset;

//initialization - connect to the database
Void OnInitADOConn ();
//query execution
_RecordsetPtr & amp; GetRecordSet (_bstr_t bstrSQL);
//executing SQL statements, Insert, Update _variant_t
BOOL the ExecuteSQL (_bstr_t bstrSQL);
Void ExitConnect ();
};

# endif//! Defined (AFX_ADOCONNARE_H__A543BEA8_DFBE_48A2_B8D5_E150D9C01566__INCLUDED_)


//adoconnARE. CPP: implementation of the CadoconnARE class. 
//
//////////////////////////////////////////////////////////////////////
//ARE sending and receiving data plate

# include "stdafx. H"
# include "NNARE. H"
# include "adoconnARE. H"

# ifdef _DEBUG
# undef THIS_FILE
The static char THIS_FILE []=__FILE__;
# define new DEBUG_NEW
# endif

//////////////////////////////////////////////////////////////////////
//Construction/Destruction
//////////////////////////////////////////////////////////////////////

CadoconnARE: : CadoconnARE ()
{

}

CadoconnARE: : ~ CadoconnARE ()
{

}

//initialization - connect to the database
Void CadoconnARE: : OnInitADOConn ()
{
//initialize the OLE/COM library environment
: : CoInitialize (NULL);

Try
{
//create a Connection object
M_pConnection. CreateInstance (" ADODB. Connection ");
//set the connection string, must be type BSTR or _bstr_t type
_bstr_t strConnect="Provider=SQLOLEDB; Server=Server; The Database=DATA; Uid=USER; The PWD=PASSWORD ";
M_pConnection - & gt; Open (strConnect, ""," ", adModeUnknown);
}
//the catching
Catch _com_error (e)
{
//display an error message
AfxMessageBox (e.D escription ());
}
}

//query execution
_RecordsetPtr & amp; CadoconnARE: : GetRecordSet (_bstr_t bstrSQL)
{
Try
{
//connect to the database, if the Connection object is empty, is to connect to the database
If (m_pConnection==NULL)
OnInitADOConn ();
//create a recordset object
M_pRecordset. CreateInstance (__uuidof (you));
//table
M_pRecordset - & gt; Open (bstrSQL, m_pConnection GetInterfacePtr (), adOpenStatic, adLockOptimistic, adCmdText);
}
//the catching
Catch _com_error (e)
{
//display an error message
AfxMessageBox (e.D escription ());
}
//return record sets
Return m_pRecordset;
}

//executing SQL statements, Insert, Update _variant_t
BOOL CadoconnARE: : the ExecuteSQL (_bstr_t bstrSQL)
{
//_variant_t RecordsAffected;
Try
{
//have to connect to the database
If (m_pConnection==NULL)
OnInitADOConn ();
//the Execute method of Connection object (_bstr_t CommandText,
//the VARIANT * RecordsAffected, long Options)
//the CommandText is command string, usually is the SQL commands,
//parameter RecordsAffected is affected by operation after completion of the number of rows,
//parameter Options said CommandText types: adCmdText - text commands; AdCmdTable - table name
//adCmdProc - stored procedure;
unknown adCmdUnknown -M_pConnection - & gt; Execute (bstrSQL, NULL, adCmdText);
return true;
}
Catch _com_error (e)
{
AfxMessageBox (e.D escription ());
return false;
}
}

Void CadoconnARE: : ExitConnect ()
{
//close the recordset and connection
If (m_pRecordset!=NULL)
M_pRecordset - & gt; Close ();
M_pConnection - & gt; Close ();
//release environment
: : CoUninitialize ();
}


Computer insert data to the SQL database, A return to success, the database without data
The same procedure to other computer B is normal
But the computer A query the database, to obtain the result set are normal
I don't know what is this the cause

CodePudding user response:

Perhaps the SQL server configuration problem, since the client to check first

CodePudding user response:

Close the UAC, firewall, anti-virus software,...
As an administrator to run
First manually executing SQL statements in the query analyzer after success, and then use the same SQL statements in your code,

CodePudding user response:

Maybe the database is read-only mode, check

CodePudding user response:

Question should be computer or database related configuration problems

CodePudding user response:

Connect to the database using the user to specify permissions without inserting table?
  • Related