Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert dsn-less to dsn

Status
Not open for further replies.

edvil

IS-IT--Management
Oct 21, 2009
7
US
Hi I have an asp page that connects to my access db.
I would like to use a dsn connection but I am running into a couple of problems
this is my original connection

Code:
Username = Request.Form("txtUsername")	
Password = Request.Form("txtPassword")

'Build connection with database
	set conn = server.CreateObject ("ADODB.Connection")		
	conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("\mydb.mdb")
	set rs = server.CreateObject ("ADODB.Recordset")

	rs.Open "SELECT * FROM mydb where username='" & Session("Username")& "'", conn, 1

This is what I am trying

Code:
Username = Request.Form("txtUsername")	
Password = Request.Form("txtPassword")
	

'Build connection with database
	set conn = server.CreateObject ("ADODB.Connection")		
	conn.Open "DSN=mydsn","UID=","Pwd=;"
	set rs = server.CreateObject ("ADODB.Recordset")

	rs.Open "SELECT * FROM mydb where username='" & Session("Username")& "'", conn, 1
 
In my opinion, a dsn-less connection is better. Can you explain why you want to change this?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
yes, I understand and agree. There are some instances when dsn-less has not worked out well with another db that I use, this db is in an AS400 box, ibm db2. In this case the dsn has worked out better
 
I created the same file structure and fields in my db2, so my thinking was, if I change the dsn-less to dsn I showld be able to use the same code
 
For a DSN connection, you need to specify the driver you are using to connect...

here's my SQL DSN code

Code:
set conn = server.createObject("ADODB.Connection")
conn.connectionString = "[COLOR=red]Driver={SQL Server}[/color];DSN=myDSN;UID=myUID;PWD=myPASS;"
conn.open "DSN=myDSN","myUID","myPASS" 
...
conn.close
set conn = nothing

I personally prefer DSN connections, as I often use the same DB for mulitple sites. Whenever I do a version upgrade and rename the db (i.e. myDB_v1.0 vs myDB_v1.1), I can simply update the DNS connection and there is never a need to touch any of the code...








--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Thank you vicvirk and thank you gmmastros.

I was able to get what I was trying to accomplish. my code was correct. the only thing is that I forgot I was not working in the actual webserver. so I added the dsn to the server and voila. Sorry rookie mistake!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top