Click here to Skip to main content
12,819,538 members (33,396 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
I am writing a database application with C# that uses an ODBC database as its data source. The point is that any time the application is installed on a different computer the ODBC connection must be done manually.
I would want to do it programmaticaly so that less hectic is placed on the user. I tried but had a security exception error which meant I do not have the right to write to the HLM.

Please is there a way out. I will be grateful of any help given. Thanx.
Posted 15-Jan-13 12:24pm
David_Wimbley 15-Jan-13 17:34pm
If you got a security exception can you not run the app as an administrator? Right click run as admin.

Or perhaps add

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

To your application manifest file?
PIEBALDconsult 15-Jan-13 18:32pm
ODBC? Why?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

What database are you using?

Is this snippet what you are looking for?

public static extern bool SQLConfigDataSource(int hwndParent, int fRequest, string lpszDriver, string lpszAttributes);
const  ODBC_ADD_DSN = 1;
const  ODBC_ADD_SYS_DSN = 4;

public object CreateOdbcDataSource()
    string driver = "Your Driver Name Here"; //Ex: Sql Server
    string odbcAttributes = "DSN=Sample" + Strings.Chr(0) + "Database=Your Database" + Strings.Chr(0) + "Description= This is a database" + Strings.Chr(0) + "Server=(local)" + Strings.Chr(0) + "Trusted_Connection=No" + Strings.Chr(0);

    SQLConfigDataSource(0, ODBC_ADD_SYS_DSN, driver, odbcAttributes);

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100