|
Create an ADOConnection whenever it's needed.
|
|
|
|
|
Hello Gerald Schwab ...
your answer is good!, but Creating an ADOConnection whenever it's need, may slow down my application, isn't it ?
tanks!
|
|
|
|
|
Is better to use the adoconnection like a global variable for your application, but you must open the adoconnection when you need, and leaving that connection open, for future use, and closing the connection when you close the Applictaion. But if your applictation need to use the connection every a long time, is better open the connection every time that you needm, but always leaving the connection like a global function.
Cheers....
Carlos Antollini.
|
|
|
|
|
Hello Carlos Antollini ....
your answer is good, too !
but, I have problem with that when I use Transaction with Option_Explicit set to ON. In some cases i should restart my application.
|
|
|
|
|
You are working with VB?
Regards!!!!
Carlos Antollini.
|
|
|
|
|
Hello, Carlos Antollini !
No,... I'm working with Delphi 5.0
Regards!!!!
|
|
|
|
|
I'm Sorry, I don't Know Nothing About Delphi....
But If you use the Connection like a Global Variable, You don't must to forguet to close the connection, when Close the Application. For other part, I don't Know what happens in Delphi. I'm Sorry Again....
Best Regards!!!!
Carlos Antollini.
|
|
|
|
|
Hello again, Carlos Antollini !
Tanks for your helps.
Regards!!!!;)
Mehrdad.
|
|
|
|
|
... trying to get a FOR XML rowset back out through ADO/ASP now, and its becoming a nightmare!
strings I select like this: SELECT '<hello/<' are just great, but something simple like:
SELECT blah
FROM blogg
FOR XML AUTO, ELEMENTS
gives me rubbish, like:
?colname??L?anothercol?a??somethingelse?andmoreshite
which isn't making much sense to me, unless its a UNICODE problem...
thanks in advance if anyone can help
Nick
|
|
|
|
|
I have an ASP page in which I am trying to start a transaction
<br />
var Conn = Server.CreateObject("ADODB.Connection");<br />
Conn.Open("MyDB");<br />
Conn.BeginTrans();<br />
Conn.Execute("sp_InsertNew " + name);<br />
The stored proc, sp_InsertNew, as you would imagine just inserts a record into a table
When I try this I get the error, "Transaction cannot start while in firehose mode."
MSDN says this is a bug with SQL Server 2000 and the Enterprise Manager. The problem is I am trying this with an ASP page and ADO connection.
Can anyone shed some light on this?
|
|
|
|
|
Im using ADO to access an SQL server and everything is working ok except
for when an error occurs.
Then the description and source properites in the error object is
*always* null.
The native error number is how it should be.
Anyone got a clue what could cause this?
(we also access the db with MFC and ODBC and there the description is correct)
/Magnus
|
|
|
|
|
Send your code snippet so we can have a look at what you are doing wrong
|
|
|
|
|
Here is the codesnippet used to get the error.
The _ConnectionPtr passed in is either the connection
pointer used to execute the command or gotten from
_RecordsetPtr->GetActiveConnection()
NativeError contains a valid number as said but all strings are NULL.
void EmitError(_ConnectionPtr piCon)
{
if(piCon == NULL)
return;
ErrorsPtr ptrErrors = piCon->Errors;
if(ptrErrors == NULL)
return;
long lCount = ptrErrors->Count;
ErrorPtr ptrError = NULL;
CString sError;
for(long n = 0; n < lCount; n++)
{
ptrError = ptrErrors->GetItem(n);
if(!(ptrError == NULL))
{
LogEmit("%s\nState: %s, Native: %d, Source: %s\n\n",
(LPCTSTR)_bstr_t(ptrError->GetDescription()),
(LPCTSTR)_bstr_t(ptrError->GetSQLState()),
ptrError->NativeError,
(LPCTSTR)_bstr_t(ptrError->GetSource())
);
}
}
}
/Magnus
|
|
|
|
|
use exception handling e.g.
try
{
HRESULT hr = piCon->....;
if (FAILED(hr))
_com_issue_error(hr);
}
catch(_com_error& e)
{
CString sBuff = GetErrorDescription(e);
AfxMessageBox(sBuff);
return;
}
catch(...)
{
AfxMessageBox("Unknown Error Occured");
return;
}
CString GetErrorDescription(_com_error& e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
_TCHAR szTemp[1024];
CString strInfo ;
wsprintf(szTemp, _T("Message : %s\n"), e.ErrorMessage());
strInfo = szTemp;
wsprintf(szTemp, _T("Code : 0x%08lx\n"), e.Error());
strInfo += szTemp;
wsprintf(szTemp, _T("Source : %s\n"), bstrSource.length() ? (LPCTSTR)bstrSource : _T("null"));
strInfo += szTemp;
wsprintf(szTemp, _T("Description : %s\n"), bstrDescription.length() ? (LPCTSTR)bstrDescription : _T("null"));
strInfo += szTemp;
return strInfo;
}
|
|
|
|
|
I do use exception handling, thats from where a try to get the ado-errors.
The problem is not catching the error but that the description field is NULL.
I can get the HRESULT, native error,.. but that are not very friendly messages.
I dont think the code that tries to dig out the error is to blame here, the problem must lie somewhere else,.......and i dont have a clue where.
/Magnus
|
|
|
|
|
Hi all,
I'm trying to use IXMLHTTPRequest to send an XML document (from a C++ client app) to a template on a SQL Server. It appears IIS support is configured properly, because putting the document directly in the url works - like this:
http://myserver/virtualdir/templates/mytemplate.xml?doc='<root/>'
The template is:
<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql'>
<sql:header>
<sql:param name='doc'>'default'</sql:param>
<sql:header>
<sql:query>
exec usp_MySP @doc
</sql:query>
<ROOT>
In code, I open an IXMLDOMDocument, and load xml into it. Then, I open an IXMLHTTPRequest and send the document:
hr = pIXMLHttpRequest->open(_bstr_t(_T("POST")),
_bstr_t(_T("http://myserver/virtualdir/templates/mytemplate.xml")),
_variant_t(VARIANT_FALSE),
_variant_t(""), _variant_t(""));
hr = pIXMLHttpRequest->setRequestHeader(_bstr_t(_T("Content-type")),
_bstr_t(_T("application/xml")));
hr = pIXMLHttpRequest->send((IDispatch *)pDoc);
The stored procedure always gets the default parameter, not whatever document I pass in.
Thanks for any help with this cryptic stuff
Cheers
NB
|
|
|
|
|
How can I check if MDAC is installed on the machine in Visual C++ ?
|
|
|
|
|
There's a registry key HKEY_CLASSES_ROOT\MDACVer.Version with a subkey CurVer with the value like MDACVer.Version.2.60.
I don't know if all MDAC version supports this key.
Volker
|
|
|
|
|
use this code on ::InitInstance
CLSID clsid;
HRESULT hr = AfxGetClassIDFromString("Datalinks", &clsid);
if(!SUCCEEDED(hr))
{
AfxMessageBox("You need to install MDAC v2.1 or higher");
return FALSE;
}
|
|
|
|
|
Hi there Guys! Hope someone out there can help!
I have a multi-threaded application that uses OLE DB and the MS Jet engine to call into a shared Access database. I have a critical section which get's locked and unlocked before and after accessing the DB, therefore stopping any other thread from accessing it whilst it is being used by another thread.
However, I am getting some errors. I initially thought it may be the critical sections, and so changed them to mutexes, but have since proved that this isn't the problem. The problem I am getting is this:
[Microsoft][ODBC Microsoft Access Driver] Could not update; currently locked by user 'me' on machine 'xxxxxx'
So silly me! I'm trying to access the database when it is apparently still locked - even though the first thread has stopped accessing it! There seems to be some latency involved in the first thread letting go of the database properly and the next one calling in.
I have thought on checking for existence of the ".ldb" lock file, but this just seems crap! Surely there is a more elegant way!? Any help/ideas would be greatly appreciated!
|
|
|
|
|
This may not be related - but
Do you call CoInitialize(NULL) and CoUnitialize() in all your Threads? This basically loads the OLE Library that OLE DB requires.
|
|
|
|
|
Perhaps calling the IIdle::Idle would remove the locks? The Jet OLE DB docs makes it clear that we should call this methods frequently.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Hi
Im using the Refresh Method With ADO C++(I had to many problems with Createparameter Method)
bstr_t bstr = L"DSN=MEAS2SQL;
pCon->Open(bstr, (BSTR)NULL, (BSTR)NULL, -1);
pCommand->ActiveConnection = pCon ;
pCommand->CommandType = ADODB::adCmdStoredProc
pCommand->CommandText = _bstr_t("URBAN");
"It works with executing a stored procedure without parameters"
But when i inlude parameters with this lines i get the error.
pCommand->Parameters->Refresh();
pCommand->Parameters("@pkMbtID") = '160';
I get the error:
error C2064: term does not evaluate to a function
I spent several hours with this Plezz Help.
PS. They say CreateParametr is Faster then Refresh Method i wonder how much faster?
|
|
|
|
|
Parameters is a collection, so you have to use.
In VB the Item property is the default property of the parameters collection.
But in C++ there are no default properties.
BTW I don't thing defaulting everthing as done in VB does the programmer
do an favour. Defaulting rules can change, because there are defined
by the type lib you are coding againts.
So if you happen to have a newer type lib installed where the default props have changed, you
will run into trouble. So I have the attitude to never depend on default probs
and methods in any language I use (VB, C++, VB script)
pCommand->Parameters->Item[_T("@pkMbtID")]->Value = _T'160'
And is your parameter really a string or is it a number ?
The Value is a _variant_t, so you can stuff in a number, if that's what you really want.
|
|
|
|
|
Hi there,
I was wondering why you would want to use an identity column as opposed to using a Primary Key or UniqueIdentifier data? What's the advatnage if any?
Where would this be suitable?
|
|
|
|