Re: SQL Server ado connect
#define CON_STR "provider=sqloledb; server=yourServer; uid=yourUID; pwd=yourPWD; database=yourDatabase;";
HRESULT hr = m_Connection->Open(_bstr_t(CON_STR), _bstr_t(""),
_bstr_t(""), adAsyncConnect);
Bayram.
Re: SQL Server ado connect
I cannot seem to get this to work. Here is the code I have tried:
BOOL CSchedulerDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
HRESULT hr;
CString strConn = "Provider=sqloledb;server=comp_acer9;database=Project_Data.mdf";
//make connection
try{
hr = m_pConnection.CreateInstance(__uuidof(Connection));
if(SUCCEEDED(hr))
{
hr = m_pConnection->Open(_bstr_t(strConn), _bstr_t(L""), _bstr_t(L""), adAsyncConnect);
if(SUCCEEDED(hr))
{
}
}
}
catch(_com_error &e)
{
_bstr_t bstrError = e.Error();
_bstr_t bstrDesc = e.Description();
TRACE(bstrError);
TRACE(bstrDesc);
}
catch(...)
{
}
return TRUE;
}
In the line
CString strConn = "Provider=sqloledb;server=comp_acer9;database=Project_Data.mdf";
I have also tried
CString strConn = "Provider=sqloledb;server=comp_acer9;uid="";pwd=""database=Project_Data.mdf";
but that did not work.
I am not sure if my spq database is set up properly and although the try block is not working it does not seem to be throwing an exception. I am not sure what to do from here.
If I open SQL server 7.0 Enterprise manager the list shows something similar to the following:
Console Root
Microsoft SQL Servers
SQL Server Group
Comp_Acer9 (Windows NT)
Databases
.........
.........
Project
Data Transformation Services
SQL 6.5
Anyway, this is the directory and if you see something wrong with what I am doing, please, I could use some help!
Mike B