DSN Util C#(Won't create)

2019-07-19 06:16发布

I was following this other post --> C# DSN Util

So I have the following code. (Slightly Modified)

OdbcConnection DbConnection = null;      
try        
{            
    DbConnection = new OdbcConnection(               
        "DataSourceName=NEWDSN;"+         
        "Driver=SQL Server;" +              
        "Description=New DSN;" +           
        "Server=<NameofServer>;");        
    DbConnection.Open();       
}         
catch (Exception e)       
{            
    Console.WriteLine(e.Message);            
    Console.ReadKey();            
    System.Environment.Exit(0);        
} 

Everything seems to work fine, I get no errors but nothing is created? I have tried troubleshooting with the following techniques

  • I am able to create one when doing it manually in the ODBC Admin tools

  • When adding "DatabaseName=blah;"

I have tried many things in this field but am unable to produce anything.

EDIT:

Hmm, there may not be a way to create one using this code. DBConnection.Open seems to be my only decent option. Is it even possible to create one that will appear in the ODBC Data Source Admin?

标签: c# dsn
1条回答
欢心
2楼-- · 2019-07-19 06:41

The code and example you are using is for opening a DSN that has already been created, not for actually creating them in the first place.

You probably need something more like this example

http://www.codeproject.com/KB/database/DSNAdmin.aspx

查看更多
登录 后发表回答