Skip to Content
avatar image
Former Member



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 ?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Jun 02, 2017 at 03:07 PM


    I think it should work if you add parameter CS=<schema name> to you connection string.



    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 06, 2017 at 08:27 PM

    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);
    Add comment
    10|10000 characters needed characters exceeded