Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ODBC databse
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 :
<?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 :
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
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 27-Mar-13 10:21am
Edited 27-Mar-13 14:59pm
v2
Comments
ryanb31 at 27-Mar-13 15:36pm
   
It means there is no odbc connection named SYBASE_TEST on your system.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

There are possible 2 reasons (as good as i know):
 
1)
It looks like you do not specify a driver for connection string.
//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 Wink | ;) Do you see the difference?
Tip: I prefer to use String.Format[^] method.
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[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 277
1 Maciej Los 210
2 BillWoodruff 195
3 DamithSL 195
4 Richard MacCutchan 178
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100