Click here to Skip to main content
Rate this: bad
good
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
BBAzar416
Comments
David_Wimbley at 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
 

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

1 solution

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

Solution 1

What database are you using?
 
Is this snippet what you are looking for?
 
[DllImport("ODBCCP32.DLL")]
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);
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 410
1 Sergey Alexandrovich Kryukov 350
2 ProgramFOX 275
3 Maciej Los 275
4 CHill60 260
0 OriginalGriff 360
1 ProgramFOX 265
2 Maciej Los 235
3 CHill60 200
4 RyanDev 170


Advertise | Privacy | Mobile
Web04 | 2.8.150331.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2015
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