Click here to Skip to main content
15,883,558 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I was trying to connect to an sql server ce database that I had created and passworded.I was able co to connect to d the database with d the assigned password successfully using visual studio but when I tried to connect to it using code I get d the ffg following error message:

Description: Provider could not set datasource,password, or username<br />
Message:IDispatch error #3105



C++
#include "stdafx.h"
#include<Ole2.h>
#include<tchar.h>
#include<strsafe.h>
#import "C:\Program Files\Common Files\System\Ado\msado15.dll" no_namespace rename("EOF","EndOfFile")

int main()
{
	_ConnectionPtr Conn = NULL;
	_CommandPtr Cmd = NULL;

	::CoInitializeEx(NULL,COINIT_MULTITHREADED);
	try
	{
		TCHAR szConnString[] = _T("Provider='Microsoft.SQLSERVER.CE.OLEDB.3.5';Persist Security Info='FALSE';Data Source='D:\\Projects\\Projects\\Maga\\MagaMy\\MyDatabase#2.sdf';");
		
		Conn.CreateInstance(__uuidof(Connection));

		Conn->Open(_bstr_t(szConnString),_bstr_t(_T("")),_bstr_t(_T("1234567890")),adConnectUnspecified);

		Conn->Close();
		
	}
	catch(_com_error e)
	{
		TCHAR szString[1000];
		_bstr_t Error = e.Description();
		TCHAR *szDescription = (TCHAR *)Error;
		const TCHAR * szError = e.ErrorMessage();
		StringCbPrintf(szString,sizeof(szString),_T("Description : %s ; Message : %s"),szDescription,szError);
		//IErrorInfo *IError = e.ErrorInfo();
		MessageBox(NULL,szString,_T("Class Creation Error"),MB_OK);
		if(Conn)
		{
			Conn->Close();
		}
	}
	
	::CoUninitialize();
	
	return 1;
}
Posted
Updated 11-Sep-14 11:23am
v4
Comments
Wendelius 11-Sep-14 15:10pm    
Could you update your question and add the code which is trying to connect to the database.
Gbenbam 11-Sep-14 17:03pm    
I have just added the Codes. So what do you think is the problem?

did you set the provider to the conectionString??
if not then try like this..

SQL
"Provider=SQLOLEDB;Data Source=.\\SQLEXPRESS;Initial Catalog=TestDB;Integrated Security=SSPI;Persist Security Info=False"
 
Share this answer
 
Comments
Gbenbam 11-Sep-14 17:04pm    
I have just added the codes. What do you think is the problem?
When using Sql Server CE database, typically you don't have to use user information in your connection string. This is because it runs in-process. So try modifying your connection string as
C++
TCHAR szConnString[] = _T("Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=D:\\Projects\\Projects\\Maga\\MagaMy\\MyDatabase#2.sdf");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900