I have written following code for connectivity
CDatabase database;
CString SqlString;
CString ssn,firstname;
CString sDriver = _T("SQL Server");
CString sDsn, sMc;
sMc.Format(_T("MERILDSK33"));
CString sFile = _T("C:\\Program Files\\Microsoft SQL Server\\MSSQL10.MSSQLSERVER\\MSSQL\\DATA\\DBTrial.mdf");
sDsn.Format(_T("ODBC;DRIVER={%s};Server=%s;Database=%s;Trusted_Connection=yes"),sDriver,sMc,sFile);
int iRec = 0;
try
{
database.Open(NULL,false,false,sDsn);
CRecordset recset(&database);
SqlString = _T("select * from dbo.Person");
recset.Open(CRecordset::forwardOnly,SqlString,CRecordset::readOnly);
while( !recset.IsEOF() )
{
recset.GetFieldValue(_T("SSN"),ssn);
recset.GetFieldValue(_T("PersonFN"),firstname);
recset.MoveNext();
}
database.Close();
}
catch(CDBException* e)
{
AfxMessageBox(e->m_strError);
}
But on database.open line I get following error
Connection failed SQL State: '08004' SQL Server Error:4060 Server rejected the connection;Access to selected database has been denied
I tried to run as administrator,but still error comes ,Server name,mdf file name and path everything is correct.Server is also in running condition.The user in which I am ruuning is same as window Authantication of SQL server.I dont know what to do?
Please help