DSN Util C#(Won't create)

ε祈祈猫儿з 提交于 2019-12-24 02:14:24

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/6615657/dsn-util-cwont-create

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!