1

This is my code:

    OdbcConnection odbcConn = new OdbcConnection("DSN=VIP_Company355");

    try
    {
        odbcConn.Open();
        int pleaseReachMe = 5;
    }
    catch (Exception ex)
    {

    }

When the debugger reaches

    odbcConn.Open(); 

It does not return, and it does not throw an exception. The documentation says that the default time out is 15 seconds. But after 15 seconds have passed, no exception is thrown. Also, if I replace my connection string with a nonsense value, it throws an error immediately.

Any ideas?

Edit:

I enabled ODBC Data Source Administrator's tracing, and it left the following in the log file:

parentProcessId 1518-2754   ENTER SQLDriverConnectW 
    HDBC                0x005BF570
    HWND                0x00000000
    WCHAR *             0x63118B34 [      -3] "******\ 0"
    SWORD                       -3 
    WCHAR *             0x63118B34 
    SWORD                       -3 
    SWORD *             0x00000000
    UWORD                        0 <SQL_DRIVER_NOPROMPT>

(only the last statement is included for brevity) It entered the SQLDriverConnectW procedure, but it never exists it.

Cloud9999Strife
  • 3,102
  • 3
  • 30
  • 43
  • WHat do you mean, it doesn't return? Does it just stay in this method? Is the `OdbcConn` within the `Main()` method? – plast1K Jan 17 '13 at 13:55
  • Yes, it just stays within the Open method. No, it is not in the main method, it is a method within a class, and I am running unit tests on that method. – Cloud9999Strife Jan 17 '13 at 14:05
  • What does `Console.WriteLine(odbcConn.ConnectionTimeout);` return? – Alex Filipovici Jan 17 '13 at 14:07
  • Try making a couple variables to use at the lowest layer of your class. I.e., make a `string connString = "DSN=VIP_Company355"` an `OdbcConnection conn = new OdbcConnection(connString);` and then use: `conn.Open();` This is just for future set-ups, and to make your life easier. – plast1K Jan 17 '13 at 14:14
  • Im sure the default is actually 30 seconds, It will only time out if it cant connect. what is it you expect to happen? – Derek Jan 17 '13 at 15:13
  • @AlexFilipovici It returns 15 – Cloud9999Strife Jan 18 '13 at 06:01
  • @Derek Well, I would think that it would open the connection, or throw an exception. I used the ODBC Data Source Administrator tool to see the available DSN's, when I use another data source like 'Excel Files', the Open method throws an exception. I wonder if I need something else to connect to this specific data source. Although, excel manages to open the data source and allows me to browse the 'tables' etc. of the flat files I want to see. – Cloud9999Strife Jan 18 '13 at 06:07

3 Answers3

1

I changed the connection string to the following:

"DSN=VIP_Company355;GR_UID=userName;GR_PWD=myPass;"

I'm not sure why the GR_ modification worked.

Cloud9999Strife
  • 3,102
  • 3
  • 30
  • 43
0

Try making a couple variables to use at the lowest layer of your class.

I.e., make a string connString = "DSN=VIP_Company355"

an OdbcConnection conn = new OdbcConnection(connString);

Then use: conn.Open();

i.e.

public void SomeFunction()
{    
    string connString = "DSN=VIP_Company355";

    if (OpenConnection(connString))
    {
        MessageBox.Show("Connection Established");
    }
}

public bool OpenConnection(string connString);
{
    try 
    {            
        OdbcConnection conn = new OdbcConnection(connString);

        conn.Open();

        return true;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message());

        return false;
    }
}

Edit:

Grammar and stuff. Just a note about making these variables at the top of the class. It's not necessary, but if you find that you are reusing your connection string or your OdbcConnection, it could be worth making constants of them, but that's all up to you.

plast1K
  • 469
  • 3
  • 13
-1
int pleaseReachMe = 5; 

is a local variable with no usage, therefore debugger breakpoint will not hit that, probably becoz that line will be removed by the compiler.

Visual Studio Debugger doesnt step into unused variable declarations

Community
  • 1
  • 1
Nasmi Sabeer
  • 1,370
  • 9
  • 21
  • I changed the code so that I use pleaseReachMe, and added other random calculations after that, still nothing. – Cloud9999Strife Jan 17 '13 at 13:53
  • The debugger should still hit that line, because it is doing something, even if it's as simple as assigning a variable to a value. – plast1K Jan 17 '13 at 14:03
  • 1
    @Plast1k, please read this link http://stackoverflow.com/questions/666624/visual-studio-debugger-doesnt-step-into-unused-variable-declarations – Nasmi Sabeer Jan 17 '13 at 14:06
  • I see that link, it does make sense, although this is not an answer to the above question. – plast1K Jan 17 '13 at 14:09