06-02-2017 3:50 PM - edited 02-03-2024 9:35 PM
hello
i'm trying to connect directly to Hana database in Visual Studio C#
in example is below i did this without database name
HanaConnection conn = new HanaConnection("UserID=Admin;Password=Money123;Server=HumanResources:30015" );
when i tried to set database name for example
HanaConnection conn = new HanaConnection("UserID=Admin;Password=Money123;Server=HumanResources:30015; Database=SBOTEST");
I have the message : database SBOTEST does not exist
the only one way is to set in querry
HanaCommand cmd = new HanaCommand("SELECT \"CardCode\" FROM SBODEMOPL.OCRD", conn);
it works
but i would like to write without set SBOTEST.OCRD
does anyone knows how to do this ?
Hi,
I think it should work if you add parameter CS=<schema name> to you connection string.
Pozdrawiam
Bartosz
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot Bartosz 🙂 ->>> Dzięki Bartek, nie mogłem tego znaleźć nigdzie 🙂
It works. !
And you might want to use the HanaConnectionStringBuilder to build the connection string. similar class exists for odbc and mssql. they simplify things for common property (server, username) and also automatically escape special characters correctly. additionnally I have added code to set the application name, which can help you when you check session/connection statisitics in hana studio.
//Using the SQL Connection string builder protect agains user injection to the connection string. For example, it will add " around a field when using special characters
//Like ; which is protected as used to separate properties.
//Additionnally on the hana database, we prevent a malicious user to use sql injection by inserting control caracters; in the username, or database
//and then use the InitString property to execute untrusted sql command.
HanaConnectionStringBuilder connString = new HanaConnectionStringBuilder();
connString.Server = this.Server;
connString.UserName = this.Username;
connString.Password = this.Password;
if (!String.IsNullOrEmpty(this.Database))
{
connString.CurrentSchema = this.Database;
}
if (!String.IsNullOrEmpty(this.AppName))
{
//InitString property of the ConnectionString Works on 85.3
connString.InitString = string.Concat("set 'APPLICATION' = '", this.AppName.Replace("'", "''"), "'");
}
connection = new HanaConnection(connString.ConnectionString);
connection.Open();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
99 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.