I am trying to create a POC for one of my projects which would allow me to connect to HIVE using an ODBC connection string.
I have been successful in using a DSN method to connect to HIVE. But this doesnt work for me cause I would need to allow create connections during run time where the connection source can be changed from one host to another.
I am using the following connection string (using the Microsoft ODBC driver) which I took from http://www.codeproject.com/Tips/738141/How-to-Communicate-to-Hadoop-via-Hive-using-NET-Cs
var conn = new OdbcConnection {
ConnectionString = #
"DRIVER={Microsoft Hive ODBC Driver};
Host=<IP>;
Port=10000;
User Name=root;Password=<PWD>;
Database=default;
HiveServerType=2;
ApplySSPWithQueries=1;
TrustedCerts=C:\Program Files\Microsoft Hive ODBC Driver\lib\cacerts.pem;
AsyncExecPollInterval=100;
AuthMech=0;
CAIssuedCertNamesMismatch=0;"
}
using(conn) {
conn.Open();
DataTable dt = new DataTable();
OdbcCommand cmd = conn.CreateCommand();
cmd.CommandText =
"SELECT * FROM categories;";
DbDataReader dr = await cmd.ExecuteReaderAsync();
dt.Load(dr);
}
When I try to open the connection, I get a network timeout.
ERROR [HY000] [Microsoft][HiveODBC] (34) Error from Hive: ETIMEDOUT.
I am not sure how to fix this up.
I found the solution for it. you are missing user name, pwd from your connection string change it as follow:
ConnectionString = #"
Dsn=Sample Microsoft Hive DSN;
applysspwithqueries=1;asyncexecpollinterval=100;
authmech=3;binarycolumnlength=32767;
caissuedcertnamesmismatch=0;
decimalcolumnscale=10;
gettableswithquery=0;
host=*******;
port=10000;
rowsfetchedperblock=10000;
trustedcerts={C:\Program Files (x86)\Microsoft Hive ODBC Driver\lib\cacerts.pem};
Schema=default;
uid=************;
pwd=************"
I found it working after going through the information in this blog post.
This is the connection string I used.
var connectionstring = #"DRIVER={Microsoft Hive ODBC Driver};
Host=******;
Port=10000;
Schema=default;
HiveServerType=2;
ApplySSPWithQueries=1;
AsyncExecPollInterval=100;
HS2AuthMech=2;
UserName=******;
trustedcerts={C:\Program Files\Microsoft Hive ODBC Driver\lib\cacerts.pem}";
Related
Is there a way to query a PostgreSQL db in C# in a database agnostic way ie without Npgsql. I want use built in .NET libraries and a connection-string that contains the DB IP, Username, Password and any other info that the connection-string might require.
You can use ODBC and construct the connection within your app. The Postgres driver has to be installed on the machine running the program. Your app would then only be using the generic ODBC classes. Below is a simple example.
using System.Data.Odbc;
string connectString = "Driver={PostgreSQL UNICODE};Port=5432;Server=localhost;Database=myDBname;Uid=myusername;Pwd=mypassword;";
OdbcConnection connection = new OdbcConnection(connectString);
connection.Open();
string sql = "select version()";
OdbcCommand cmd = new OdbcCommand(sql, connection);
OdbcDataReader dr = cmd.ExecuteReader();
dr.Read();
string dbVersion = dr.GetString(0);
When use Oledb c# connection
I noticed that a lot connection using file.
But how to connect to localhost using oledb?
I created database and tables using Microsoft SQL Server Management that connect with SQL Express and using window authentication
When using this function i don't know how should convert to connect to localhost
//Want the connString to connect localhost instead of file
public static string connString = #"Provider=Microsoft.JET.OLEDB.4.0;data source=" + Path + "\\database\\errDB.mdb";
public static OleDbConnection connection;
public myFunction()
{
string sqlString = "SELECT name,contact,accessLevel,Crudential_ID FROM errors where Crudential_ID =#ID";
connection = new OleDbConnection(connString);
OleDbCommand command = new OleDbCommand(sqlString, connection);
//Open connection
connection.Open();
command.Parameters.Add("#ID", OleDbType.VarChar);
command.Parameters["#ID"].Value = "test";
//Read from database
OleDbDataReader reader = command.ExecuteReader();
if(reader.HasRows)
{
.....
}
connection.Close();
}
connectionstrings.com - true to its name - is indispensable when you frequently need to construct connection strings. For your specific case, this would be the relevant section.
Based on that, your connection string should look something like this:
Provider=SQLNCLI11;Server=.\SQLEXPRESS;Database=SOMEDATABASE;Trusted_Connection=yes;
To break it down:
SQLNCLI11 is the SQL Native Client OLEDB provider. You can see available providers in SQL Management Studio, under Server Objects > Linked Servers > Providers.
.\SQLEXPRESS is your servername and instance. The . is shorthand for localhost (you can also use localhost if you prefer), and SQLEXPRESS is the default instance name that SQL Express installs under.
SOMEDATABASE - whatever your database name is.
Trusted_Connection=yes - Use windows authentication. Sometime you see it as Integrated Security=SSPI. They are one and the same.
If you are using SQL Express then I would suggest using a System.Data.SqlClient.SqlConnection object to make your connection. You will only need your server name to connect.
Server=ServerName\SQLEXPRESS;Database=Blah;User ID=user;Password=pw
I have already installed mysql connector 6.7.4 and following reference is already added in code
using MySql.Data.MySqlClient;
I am using this string to connect database
string connStr = ("Provider = MySQLProv; SERVER =localhost; DATABASE=test;User ID=root;Password=");
OdbcConnection conn1 = new OdbcConnection();
conn1.ConnectionString = connStr;
OdbcCommand cmd1 = conn1.CreateCommand();
cmd1.CommandText = "SELECT * FROM patientinfo WHERE medicareNo = " + "" + p.getMedicare() + "";
conn1.Open();
It says,
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
What did i do wrong ?? I have sqltest database with the required table.
update: odbc connector 5.2 is installed and used as:
using System.Data.Odbc.OdbcConnection
When installing your MySql Server did you install the service in a specific port? this could be a potential problem, just in case try this connection string which specifies the port
3306 is the default MySql port, yours may differ if you specified it during installation.
Server=yourServerName;Port=3306;Database=test;Uid=root;
Pwd=yourPassword;
I have an MSDE installed and I have a DB for it. And on a client computer an ODBC alias (x). I want to connect to this using a .NET4 program written in C#. What connection string should I use if I have only a login name (y) and a password (z)?
Or am I to extract server and database name from the registry?
Try this:
Provider=MSDASQL.1;Data Source=x
where x is your ODBC alias. You will need to add security information to this, as per normal.
http://support.microsoft.com/kb/310988
The example #4 is for the DSN use.
{
OdbcConnection cn;
OdbcCommand cmd;
string MyString;
MyString="Select * from Customers";
cn= new OdbcConnection("dsn=myDSN;UID=myUid;PWD=myPwd;");
cmd=new OdbcCommand(MyString,cn);
cn.Open();
MessageBox.Show("Connected");
cn.Close();
}
I am new to SmartDeviceProject. So When i try to connect MySQL to my project, MissingManifestResourceException through in Connection.open in below code?.
string connectionString = "server=192.168.1.100;database=mcubic;User Name=mcubic;Password=mcs#2011$;";
string query = "select b.Outlet_Master_Name from mcs_user_outlet a,outlet_master b where a.Mcs_User_Outlet_User_Id=3 and a.Mcs_User_Outlet_Outlet_Id = b.Outlet_Master_Id";
MySqlConnection connection = new MySqlConnection(connectionString);
MySqlCommand command = new MySqlCommand(query, connection);
connection.Open();
MySqlDataReader Reader = command.ExecuteReader();
while (Reader.Read())
{
comboBox1.Items.Add(Reader[0].ToString());
}
connection.Close();
How do i solve this,. I am imported MySql.Data.CF.dll for this project.
Via Krish Kapadia from MSDN forums:
Solution :
MySql's version 5.2.7.0 is the stable version. I use dll of this version. Other versions have many problems. so first I download dll of that version from mysql site.
here is the link :
http://dev.mysql.com/downloads/connector/net/5.2.html
I have inserted one entry in 'mysql.user' table in which hostname will be '%' (means any user can connect to mysql). If you don't want to insert entry with hostname then you have to insert for all ip addresses who should be allowed to connect to mysql.
After inserting entry in 'mysql.user', I restarted MySQL service.
And then trying to connect to mysql and Connected....
source:
http://social.msdn.microsoft.com/Forums/eu/netfxcompact/thread/66f6386a-9963-4c2f-8d39-1c507a26a6c7