locked
Best way to connect Sybase datbase from .NET RRS feed

  • Question

  • User-1340937076 posted

    Hi,

    I want to connect Sybase database using Visual Studio 2010. Please let me know the best way how we can connect.

    Regards, Pravin

    Friday, August 19, 2011 7:18 AM

Answers

  • User-1340937076 posted

    I coded following way and it is working fine -

    <meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" /> <title></title> <meta name="GENERATOR" content="OpenOffice.org 3.1 (Win32)" />

    using Sybase.Data.AseClient;

    public class DBHelper {

    private AseConnection _dbConn;

    public DBHelper() {}

    private string GetConnectionString() {

    if (ConfigurationManager.ConnectionStrings["sybase-connectionstring"] != null)

    return ConfigurationManager.ConnectionStrings["sybase- connectionstring"].ConnectionString;

    else

    return "";

    }

    private void OpenConnection() {

    if (_dbConn != null) {

    if (_dbConn.State == ConnectionState.Closed) {

    _dbConn.Open();

    }

    }

    }

    public IDataReader ExecuteReader(string query) {

    _dbConn = new AseConnection(GetConnectionString());

    AseCommand dbCommand = new AseCommand(query, _dbConn);

    dbCommand.CommandType = CommandType.Text;

    OpenConnection();

    return dbCommand.ExecuteReader(CommandBehavior.CloseConnection);

    }

    }

    Use following code to Execute the Query

    DBHelper objTest= new DBHelper();

    IDataReader dr= objTest.ExecuteReader("Select * from Customer");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 25, 2011 8:19 AM

All replies

  • Friday, August 19, 2011 7:34 AM
  • User-718146471 posted

    Pravin, I would suggest you look at connection strings website since they have a huge repository of every connection string out there using best practices. I would recommend placing this into your web config and then reference it in your code. Also, you may want to encrypt that section of your web.config file to keep the connection string secure.

    Sybase Advantage: http://connectionstrings.com/sybase-advantage

    Sybase Adaptive: http://connectionstrings.com/sybase-adaptive 

    Friday, August 19, 2011 7:35 AM
  • User-718146471 posted

    Reading connection string from web config file: http://msdn.microsoft.com/en-us/library/ms178411.aspx

    Encrypting connection string in web.config: http://chiragrdarji.wordpress.com/2008/08/11/how-to-encrypt-connection-string-in-webconfig/

    Friday, August 19, 2011 7:37 AM
  • User-1340937076 posted

    Thank you all... I will see and let you know.

    Friday, August 19, 2011 9:11 AM
  • User-1340937076 posted

    I coded following way and it is working fine -

    <meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8" /> <title></title> <meta name="GENERATOR" content="OpenOffice.org 3.1 (Win32)" />

    using Sybase.Data.AseClient;

    public class DBHelper {

    private AseConnection _dbConn;

    public DBHelper() {}

    private string GetConnectionString() {

    if (ConfigurationManager.ConnectionStrings["sybase-connectionstring"] != null)

    return ConfigurationManager.ConnectionStrings["sybase- connectionstring"].ConnectionString;

    else

    return "";

    }

    private void OpenConnection() {

    if (_dbConn != null) {

    if (_dbConn.State == ConnectionState.Closed) {

    _dbConn.Open();

    }

    }

    }

    public IDataReader ExecuteReader(string query) {

    _dbConn = new AseConnection(GetConnectionString());

    AseCommand dbCommand = new AseCommand(query, _dbConn);

    dbCommand.CommandType = CommandType.Text;

    OpenConnection();

    return dbCommand.ExecuteReader(CommandBehavior.CloseConnection);

    }

    }

    Use following code to Execute the Query

    DBHelper objTest= new DBHelper();

    IDataReader dr= objTest.ExecuteReader("Select * from Customer");

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 25, 2011 8:19 AM