DB Connection with ODBC ASP.NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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!!!!
 
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?
 
Back
Top