如何在控制台应用程序中按数据源名称连接数据库(c#)

时间:2016-02-04 10:34:03

标签: c# sql-server odbc jdbc-odbc

我想使用连接到数据库 数据源名称:用于钻取DSN的MapR ODBC驱动程序,我在ODBC DATA SOURCE ADMINSTRATOR(64位)中创建了系统DSN名称。

我的代码是:

try
{
    string connectionString = "DRIVER={org.apache.drill.jdbc.Driver};Data Source=MapR ODBC Driver for Drill DSN ; Initial Catalog=cp;Integrated Security=True ";
    string sql = "SELECT * from cp.`employee.json`";
    OdbcConnection conn = new OdbcConnection(connectionString);
    conn.Open();
    OdbcCommand comm = new OdbcCommand(sql, conn);
    OdbcDataReader dr = comm.ExecuteReader();
    while (dr.Read())
    {
        Console.WriteLine(dr.GetValue(0).ToString());
        Console.WriteLine(dr.GetValue(1).ToString());
        Console.WriteLine(dr.GetValue(2).ToString());
     }

     conn.Close();
     dr.Close();
     comm.Dispose();
     conn.Dispose();
}
catch (Exception ex)
{
     Console.WriteLine(ex.Message);
     Console.ReadKey();
}

当我运行此代码时,它显示错误:

  

找不到数据源名称且未指定默认驱动程序。

请帮帮我。

0 个答案:

没有答案