Results 1 to 2 of 2

Thread: Create DSN

  1. #1

    Thread Starter
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565

    Create DSN

    Can anybody give me an example of how to create a DSN in code using SQLConfigDataSource please.

    Banging my head against a brick wall!!
    VB6 sp5, SQL Server 2000, C#

    There are no stupid questions. Only stupid people.

  2. #2
    Addicted Member DJ_Catboy's Avatar
    Join Date
    Jan 2003
    Location
    Suffolk, UK
    Posts
    159
    Hi,

    I use this code to create a DSN... you can control if it is a user or system dsn by opening the Registry.LocalMachine or Registry.CurrentUser methods respectively. All I did to check this was create a DSN, look at what happens in the registry, then take each value from the registry and ensure that the code below actually populates the registry with the relevant information.

    Also, I think you need to include the Microsoft.Win32.Registry or something like that at the top of your code.

    Code:
    RegistryKey r = Registry.LocalMachine.CreateSubKey("SOFTWARE\\ODBC\\ODBC.INI\\DSN NAME");
    r.SetValue("BufferSize","65535");
    r.SetValue("Description","Connection");
    r.SetValue("Driver","C:\\Windows\\System32\\msorcl32.dll");
    r.SetValue("DSN","DSN NAME");
    r.SetValue("GuessTheColDef","0");
    r.SetValue("PWD","");
    r.SetValue("Remarks","0");
    r.SetValue("SERVER","oracleserver");
    r.SetValue("StdDayOfWeek","1");
    r.SetValue("StripTrailingZero","0");
    r.SetValue("SynonymColumns","1");
    r.SetValue("UID","me");
    r.Close();
    
    r = Registry.LocalMachine.OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources\\",true);
    r.SetValue("DSN NAME","Microsoft ODBC for Oracle");
    r.Close();
    Hope this helps?

    DJ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width