473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

DB Connection with ODBC ASP.NET

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
Oct 25 '06 #1
3 1356
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" <MA**@discussions.microsoft.comwrote in message
news:A6**********************************@microsof t.com...
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

Oct 25 '06 #2
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;databas e=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!!!!

Oct 25 '06 #3
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" <MA**@discussions.microsoft.comwrote in message
news:A6**********************************@microsof t.com...
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


Oct 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: SerGioGio | last post by:
Hello, I am going nuts. I am trying to connect to my local ORACLE instance using ODBC. It used to work few weeks ago, but it fails now. Connection with: - SQL*plus: connection works! -...
14
by: jj | last post by:
Is it possible to call a remote php script from within Access? I'm thinking something like: DoCMD... http://www.domain.com/scripts/dataquery.php DoCmd.OpenQuery "update_data", acNormal, acEdit...
5
by: Alec | last post by:
Hi All, I am currently trying to link in Access 97 to a table in a MSSQL 7 server. Initially the link is fine, however, when I close the access database and re-open it from the same network...
9
by: mcbill20 | last post by:
Hello all. I just installed Oracle 10g developer tools on a machine running XP Pro and Office XP. Before this I had just the Oracle 9 client installed. I the previous configuration, I was able to...
4
by: Matthew Wells | last post by:
FIRST OF ALL, I APPRECIATE PEOPLE SENDIUNG ME LINKS TO WEB SITES FOR CONNECTION STRINGS BUT AS I'VE SAID BEFORE THAT IS NOT WHAT I NEED. I CAN EASILY OPEN AN ADO CONNECTION OBJECT TO AS400. I...
8
by: John Smith | last post by:
How do I connect to a FoxPro 7 database?
2
by: Ben | last post by:
Hi, I have a problem connecting to Oracle using and ODBC connection in a ASP.Net web page. The TNS Names works fine because when I create a DSN it works, and it works in SQL Plus. Here are...
8
by: Greg Strong | last post by:
Hello All, The short questions are 1 Do you know how to make DSN connection close in Access to Oracle 10g Express Edition? &/or 2 Do you know how to make a DSN-less pass-through query...
7
by: Bill Nguyen | last post by:
I have this connection string using ODBC DSN Dim FactorJaco As String = "dsn=jaco;catalog=factor;uid=user;pwd=passord" This requires an ODBC DSN (jaco) at every client PC. I need to use DSN-less...
0
bartonc
by: bartonc | last post by:
This is a work in progress (current and active). There are some issues to resolve in supporting multiple connection types and I plan to add PySQLite to the mix. The this update is due to my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.