Create Access data source name dynamically
To create a DSN at run time you could use the SQLConfigDataSource API. Internally this information is stored in the registry. The syntax is attached below
SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)\0","DSN=TestDB\0DBQ=D:\\Database\\Friends.mdb\0DEFAULTDIR=D:\\DATABASE\0\0");
The problem is that if you want to accept the values from the user or set these values at run time by passing CString or char* will not work. This is because, when sprintf encounters a /0 it assumes it is the end of the string and ignores the rest of the data.
As a workaround you have to use the below mentioned code.
The following code places : where a /0 is expected and there is a loop which replaces a ":" with "/0". You will not be in a position to use sprintf because, when it encounters a /0 it assumes it is the end of the string and ignores the rest of the data.
char* szDesc;
int mlen;
szDesc=new char[256];
sprintf(szDesc,"DSN=%s: DESCRIPTION=TOC support source: DBQ=%s: FIL=MicrosoftAccess: DEFAULTDIR=D:\\Database:: ","TestDB","D:\\Friends.mdb");
mlen = strlen(szDesc);
for (int i=0; i<mlen; i++)
{
if (szDesc[i] == ':')
szDesc[i] = '\0';
}
if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))
MessageBox(hwnd,"Failed","INFORMATION",MB_OK);
else
MessageBox(hwnd,"Sucess","INFORMATION",MB_OK);

Comments
cXiwwH NI HZ VwK Kyfe XH
Posted by TJXckuLtHs on 02/17/2013 01:27pmorder tramadol online tramadol withdrawal for dogs - tramadol withdrawal long
ReplyGoal
Posted by snareenactina on 11/02/2012 04:44pmFrance is one of Europeââ¬â¢s biggest players in the Information and Communications Technologies (ICT) segment because of its large pool of skilled workforce and a strong proclivity for innovation. alcippe This does not mean that equilibrating forces do not exist. It means only that we must consider open ended processes in markets. This is not a new proposition. Adam Smith, the founder of economics as a distinct discipline, thought in evolutionary and process orientated terms. vivienne spiked warrant noble stolem
ReplySame solution using a pointer
Posted by Legacy on 12/15/2002 12:00amOriginally posted by: Juan Subotich
Replyabou access connectivity
Posted by Legacy on 09/07/2002 12:00amOriginally posted by: sachin
hi
Replythis is sachin
and i want to connect database as access
but it gives error so tell me the proper way to connect it
Java-Access combination
Posted by Legacy on 06/12/2002 12:00amOriginally posted by: sanjay
hi
Replythis is sanjay
presently i am doing a project on java which has backend as instant db but i want to replace it with access and things should be done dynamically.if any help plz mail me asap
thank u.
The Same Problem Of UID,PWD
Posted by Legacy on 05/26/2002 12:00amOriginally posted by: Noura
The Same Problem Of UID,PWD
I need My client to connect to sql server using ODBC using the function SQLConfigDataSource every thing is OK but I can't specify user and password for this connection ...
ReplyWhen not writting UID,PWD attributes ,An authentication Dialog box displayed for asking the user to verify the user and password....and it's not desired to display such a message...
I need Help....PLZ
Adding UID and PWD fails
Posted by Legacy on 04/11/2002 12:00amOriginally posted by: Rajesh
When I create a DSN for SQL Server everything works fine, except a UID and PWD is specified. If they are not specified registration succeeds using Win NT Login as the Login for SQL Server. Has anybody tried this?
ReplyCreating MDB with password Dynamically
Posted by Legacy on 02/15/2002 12:00amOriginally posted by: nagendra
i 'am able to create a mdb dynamically using CREATE_DB in SQLConfigDataSource
can any one help me create mdb with password dynamically
ReplyHow can i see a report from access in VC++ using ADO?
Posted by Legacy on 01/20/2002 12:00amOriginally posted by: Nuno Rapaz
How can i see a report from access in VC++ using ADO?
I don't no very well how reports do, but what i want is to execute querys from VC++ in reports from access.
I can do it in tables but i don't no if it's possible to do it in reports.
thanks
ReplyMs Access 2000 Data Types
Posted by Legacy on 10/29/2001 12:00amOriginally posted by: Suji
Hi
ReplyThis is Suji
I am Using MS Access 2000 as Backend for Java Applications.
If you have any idea on Ms Access DataTypes those will be used in Java Programming pl tell me.
Or if u found any web page contains brief Description about Ms Access 2000 Datatypes pl suggest me
Thanksinadvance
Yours
Suji
Loading, Please Wait ...