none
Why this ODBC connection doesn't give any thing only hung the PC RRS feed

  • Question

  • Imports

    System.Data

    Imports

    Microsoft.Data.Odbc

    Imports

    System.Data.SqlClient

    Public

    Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim cn As OdbcConnection

    cn =

    New OdbcConnection("Driver={Microsoft ODBC for Oracle};Server=gupmxesapp01:9001\maximo;Uid=myID;Pwd=MyPWD")

    Dim myString As String = "Select * from maximo_gup_resp"

    Dim cmd As OdbcCommand = New OdbcCommand(myString)

    Try

    cn.Open()

    MsgBox(

    "Connected")

    Catch ex As Exception

    MsgBox(ex.Message)

    Finally

    cn.Close()

    End Try

    End Sub

    End

    Class

    Sunday, October 6, 2013 2:29 PM

Answers

  • Hello,

    Welcome to this forum.

    I am a bit confused about what you want.

    If it is that the program throws any error. If it is, my suggestion is that to debug the program step by setp to see which line the error occurs and what the error message is. For the error, we can post it to this forum or search it online for a solution. And more information regarding Odbc:

    http://msdn.microsoft.com/en-us/library/System.Data.Odbc.aspx

    Or if it is that you want to get the data in table ‘maximo_gup_resp’. If it is, I think we have to write some more codes to fetch the data.

    There are two ways to fetch data from database with ADO.NET (ODBC belongs ADO.NET).

    Using OdbcDataReader:

    public static void ReadData(string connectionString)
    
    {
    
        string queryString = "SELECT DISTINCT CustomerID FROM Orders";
    
    
        using (OdbcConnection connection = new OdbcConnection(connectionString))
    
        {
    
            OdbcCommand command = new OdbcCommand(queryString, connection);
    
    
            connection.Open();
    
    
            // Execute the DataReader and access the data.
    
            OdbcDataReader reader = command.ExecuteReader();
    
            while (reader.Read())
    
            {
    
                Console.WriteLine("CustomerID={0}", reader[0]);
    
            }
    
    
            // Call Close when done reading.
    
            reader.Close();
    
        }
    
    }
    

    Using OdbcDataAdapter:

    public DataSet GetDataSetFromAdapter(
        DataSet dataSet, string connectionString, string queryString)
    {
        using (OdbcConnection connection = 
                   new OdbcConnection(connectionString))
        {
            OdbcDataAdapter adapter = 
                new OdbcDataAdapter(queryString, connection);
    
            // Open the connection and fill the DataSet. 
            try
            {
                connection.Open();
                adapter.Fill(dataSet);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // The connection is automatically closed when the 
            // code exits the using block.
        }
        return dataSet;
    }
    

    If I have misunderstood, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, October 7, 2013 2:40 AM
    Moderator

All replies

  • Imports System.Data

    Microsoft.Data.Odbc

    Imports

    System.Data.SqlClient

    Public

    Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim cn As OdbcConnection

    cn =

    New OdbcConnection("Driver={Microsoft ODBC for Oracle};Server=gupmxesapp01:9001\maximo;Uid=myID;Pwd=myPWD")

    Dim myString As String = "Select * from maximo_gup_resp"

    Dim cmd As OdbcCommand = New OdbcCommand(myString)

    Try

    cn.Open()

    MsgBox(

    "Connected")

    Catch ex As Exception

    MsgBox(ex.Message)

    Finally

    cn.Close()

    End Try

    End Sub

    End

    Class

    Imports
    Sunday, October 6, 2013 2:27 PM
  • Hello,

    Welcome to this forum.

    I am a bit confused about what you want.

    If it is that the program throws any error. If it is, my suggestion is that to debug the program step by setp to see which line the error occurs and what the error message is. For the error, we can post it to this forum or search it online for a solution. And more information regarding Odbc:

    http://msdn.microsoft.com/en-us/library/System.Data.Odbc.aspx

    Or if it is that you want to get the data in table ‘maximo_gup_resp’. If it is, I think we have to write some more codes to fetch the data.

    There are two ways to fetch data from database with ADO.NET (ODBC belongs ADO.NET).

    Using OdbcDataReader:

    public static void ReadData(string connectionString)
    
    {
    
        string queryString = "SELECT DISTINCT CustomerID FROM Orders";
    
    
        using (OdbcConnection connection = new OdbcConnection(connectionString))
    
        {
    
            OdbcCommand command = new OdbcCommand(queryString, connection);
    
    
            connection.Open();
    
    
            // Execute the DataReader and access the data.
    
            OdbcDataReader reader = command.ExecuteReader();
    
            while (reader.Read())
    
            {
    
                Console.WriteLine("CustomerID={0}", reader[0]);
    
            }
    
    
            // Call Close when done reading.
    
            reader.Close();
    
        }
    
    }
    

    Using OdbcDataAdapter:

    public DataSet GetDataSetFromAdapter(
        DataSet dataSet, string connectionString, string queryString)
    {
        using (OdbcConnection connection = 
                   new OdbcConnection(connectionString))
        {
            OdbcDataAdapter adapter = 
                new OdbcDataAdapter(queryString, connection);
    
            // Open the connection and fill the DataSet. 
            try
            {
                connection.Open();
                adapter.Fill(dataSet);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // The connection is automatically closed when the 
            // code exits the using block.
        }
        return dataSet;
    }
    

    If I have misunderstood, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, October 7, 2013 2:40 AM
    Moderator