DB Connection with ODBC ASP.NET

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
 
G

Guest

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!!!!
 
G

Guest

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top