DB Connection with ODBC ASP.NET

Discussion in 'ASP .Net' started by =?Utf-8?B?TUFUVA==?=, Oct 25, 2006.

  1. Using ASP.NET I would like to connect to a database using a System DSN in
    ODBC. Will this allow me to make the connection without having to specify in
    the code the server, user, password...etc...? Could someone please give me
    an example of a simple query using this method
    Thanks
    MATT
     
    =?Utf-8?B?TUFUVA==?=, Oct 25, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?TUFUVA==?=

    sloan Guest

    http://www.connectionstrings.com/

    this has a
    DSN
    ODBC

    since I don't connect that way, I'm not sure if it has exactly what you
    want.

    but its a hint.


    "MATT" <> wrote in message
    news:...
    > Using ASP.NET I would like to connect to a database using a System DSN in
    > ODBC. Will this allow me to make the connection without having to specify

    in
    > the code the server, user, password...etc...? Could someone please give

    me
    > an example of a simple query using this method
    > Thanks
    > MATT
     
    sloan, Oct 25, 2006
    #2
    1. Advertising

  3. Thanks for your reply. I guess the problem is not with my connection string.
    My Code is below.
    1) i get an error at the SqlDR = SqlDT.rows(0)
    error: "System.NullReferenceException: Object reference not set to an
    instance of an object."

    2) Is there a way to connect to the DB without having to code in the
    username, password, database, etc.... as in, use the ODBC DataSource Name?


    CODE:

    Dim DbConn As New
    SqlConnection("server=localhost\SQLEXPRESS;database=LoginTest;user=sa;pwd=mattsa")
    Dim SqlStr As String = "Select * from Users where UName = 'user' "

    Dim SqlCmd As New SqlCommand(SqlStr, DbConn)

    Dim SqlDA As New SqlDataAdapter(SqlCmd)

    Dim sqlDS As New DataSet("Users")
    SqlDA.Fill(sqlDS)

    Dim SqlDT As DataTable
    SqlDT = sqlDS.Tables("Users")

    Dim SqlDR As DataRow
    SqlDR = SqlDT.Rows(0) <--PROBLEM IS HERE!!!!
     
    =?Utf-8?B?TUFUVA==?=, Oct 25, 2006
    #3
  4. Update:
    I am able to connect to the DB now. I found my mistakes.

    Still, i would like to be able to connect using the ODBC DSN without coding
    the password/user

    This is my code:

    WORKS: Dim DbConn As New
    SqlConnection("server=Matthew\SQLEXPRESS;database=LoginTest;user=logintest;pwd=test")

    DOES NOT WORK: Dim DbConn As New ODBCConnection("DSN=LoginTest;")

    error: User '' is not associated with a trusted SQL Connection

    why can't it use the credentials i set up in the "LoginTest" DSN? Is there
    another way?

    "sloan" wrote:

    > http://www.connectionstrings.com/
    >
    > this has a
    > DSN
    > ODBC
    >
    > since I don't connect that way, I'm not sure if it has exactly what you
    > want.
    >
    > but its a hint.
    >
    >
    > "MATT" <> wrote in message
    > news:...
    > > Using ASP.NET I would like to connect to a database using a System DSN in
    > > ODBC. Will this allow me to make the connection without having to specify

    > in
    > > the code the server, user, password...etc...? Could someone please give

    > me
    > > an example of a simple query using this method
    > > Thanks
    > > MATT

    >
    >
    >
     
    =?Utf-8?B?TUFUVA==?=, Oct 25, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Igor
    Replies:
    0
    Views:
    10,110
  2. HB
    Replies:
    7
    Views:
    3,806
    Kevin Spencer
    Feb 19, 2004
  3. guizonatto
    Replies:
    0
    Views:
    2,857
    guizonatto
    Mar 27, 2008
  4. EDDIE
    Replies:
    2
    Views:
    442
    EDDIE
    Dec 27, 2004
  5. Wes Gamble
    Replies:
    1
    Views:
    186
    Gerardo Santana Gómez Garrido
    Apr 5, 2006
Loading...

Share This Page