Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting this error while trying to connect Sybase databse from Visual Studio 2010 in C# code.

My App.Config file is like this :
C#
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="DSN" value="SYBASE_TEST"></add>
    <add key="Database" value="MYDB"></add>
    <add key="UserId" value="uid"></add>
    <add key="Password" value="pwd"></add>
  </appSettings>
</configuration>


And my entire C# code is like this :
C#
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Odbc;
namespace SybaseConsoleApp
{
    class Program
    {
        static string dsn = ConfigurationManager.AppSettings["DSN"];
        static string database = ConfigurationManager.AppSettings["Database"];
        static string userId = ConfigurationManager.AppSettings["UserId"];
        static string password = ConfigurationManager.AppSettings["Password"];        static void Main(string[] args)
        {
            //string connStr = "Driver={Sybase System 11};SRVR=" + dsn + ";DB=" + database + ";UID=" + userId + ";PWD=" + password;
            string connStr = "DSN=" + dsn + ";Uid=" + userId + ";Pwd=" + password + ";Database=" + database;
            OdbcConnection odbcConn = new OdbcConnection();
            odbcConn.ConnectionString = connStr;
            odbcConn.Open();
            ...........
            ...........
            odbcConn.Close();
        }
    }
}


And I'm getting the error at line
C#
odbcConn.Open();


I'm working in a remote machine and Sybase is in another remote machine.
Please help me as soon as possible.
Thanks in Advance.
Posted
Updated 27-Mar-13 13:59pm
v2
Comments
ZurdoDev 27-Mar-13 15:36pm    
It means there is no odbc connection named SYBASE_TEST on your system.

1 solution

There are possible 2 reasons (as good as i know):

1)
It looks like you do not specify a driver for connection string.
C#
//string connStr = "Driver={Sybase System 11};SRVR=" + dsn + ";DB=" + database + ";UID=" + userId + ";PWD=" + password;
            string connStr = "DSN=" + dsn + ";Uid=" + userId + ";Pwd=" + password + ";Database=" + database;

Have a look at commented line and line below this line ;) Do you see the difference?
Tip: I prefer to use String.Format[^] method.
C#
string connStr = Format("DSN={0};Uid={1};Pwd={2};Database={3}",dsn, userId, password, database);

If it not helps, please, see these:
http://www.connectionstrings.com/sybase-adaptive[^]
http://www.connectionstrings.com/sybase-advantage[^]
How to check if DSN has been properly set up? Using odbcad32.exe application. Read this: http://support.microsoft.com/kb/942976[^]

2)
DSN is not availible for some Windows users, because of DSN is User DSN, not system DSN.
Please, read this: http://digital.ni.com/public.nsf/allkb/852559036FB6447380256ADF007C3964[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900