Open a database without a data source (dsnless connection)

Source: Internet
Author: User
Tags dsn include join connect mysql access database
Each program that needs to connect to the database must first open it on the server. There are many ways to do this!

Using System Data Source (DSN)
This must be set on the server. This is the best and fastest way to access data. Because it only needs to authenticate on the server on the line, do not need to join.

Working with file data sources
This is not a recommended method. Because of this, all users are limited! Does not apply to the network at all.

No need for DSN joins
This method does not need to set anything in the server, as long as the database exists on the line! Of course you have to have access to the password.
This is a no way, because there is no DSN setting on the server, and the speed is not set DSN fast, because each time you must connect with the server

Microsoft has an article on this in
Http://support.microsoft.com/support/kb/articles/q193/3/32.asp
Here all the Dsnless join code. We are here to say only a small part, if we think that we are not clear to go there to see English version!
Ha ha.

Dsnless connection requires you to know the name of the database file (i.e. file based databases like Access, Paradox, FoxPro, etc.) or the server address of the database (as is the case with SQL Server). You must also have permission to open the database, such as passwords and user names. With these you can open the database! Hey!

But be aware that if you are using an Access database you must know its absolute path, just like "C:\thatserver\account17\nwind.mdb". However, the Sever.mappath method can convert a relative path to an absolute path. We don't have to worry about it!

Here is an example using Dsnless to access the database named Nwind.mdb. File name is nwind.asp


<HTML><HEAD>
<TITLE>nwind.asp</TITLE>
<body bgcolor= "#FFFFFF" ></HEAD>
<%
accessdb= "Nwind.mdb"
mydsn= "Driver={microsoft Access DRIVER (*.mdb)};"
MYDSN=MYDSN & "dbq=" & Server.MapPath (ACCESSDB)
Mysql= "SELECT * FROM Customers"

Call Query2table (MYSQL,MYDSN)
%>
<!--#include virtual= "/learn/test/lib_dbtable.asp"-->
</BODY>
</HTML>

The following example uses DSN to access SQL Server with a file name of sqldsn.asp


<HTML><HEAD>
<TITLE>sqldsn.asp</TITLE>
<body bgcolor= "#FFFFFF" ></HEAD>
<%
accessdb= "Nwind.mdb"
Mydsn= "Dsn=student;uid=student;pwd=magic"
Mysql= "SELECT * From Publishers where state= ' NY '"

Call Query2table (MYSQL,MYDSN)
%>
<!--#include virtual= "/learn/test/lib_dbtable.asp"-->
</BODY>
</HTML>
The following example is a way to access a SQL Server database using Dsnless.



<HTML><HEAD>
<TITLE>sqlDSNless.asp</TITLE>
<body bgcolor= "#FFFFFF" ></HEAD>
<%

mydb= "Provider=msdasql;driver={sql Server};"
Mydb=mydb & "server=sql2.datareturn.com;database=;"
Mydb=mydb & "Uid=student; Pwd=magic; "

Mysql= "SELECT * From Publishers where state= ' NY '"

Call Query2table (MYSQL,MYDB)
%>
<!--#include virtual= "/learn/test/lib_dbtable.asp"-->
</BODY>
</HTML>
The Include file lib_dbtable.asp is the following:


<%
Sub Query2table (Inputquery, INPUTDSN)
Dim conntemp, Rstemp
Set Conntemp=server.createobject ("Adodb.connection")
Conntemp.open INPUTDSN
Set Rstemp=conntemp.execute (Inputquery)
Howmanyfields=rstemp.fields.count-1%>
<table border=1><tr>
<% ' put headings on the Table of Field Names
For i=0 to Howmanyfields%>
<td><b><%=rstemp (I) .name%></b></td>
<% Next%>
</tr>
<% ' Now lets grab the records
Do as not rstemp.eof%>
<tr>
<% for I = 0 to Howmanyfields
Thisvalue=rstemp (I)
If IsNull (Thisvalue) Then
Thisvalue= ""
End If%>
&LT;TD valign=top><%=thisvalue%></td>
<% Next%>
</tr>
<%rstemp.movenext
Loop%>
</table>
<%
Rstemp.close
Set rstemp=nothing
Conntemp.close
Set conntemp=nothing
End Sub%>
Do you see what you've got? Hey, not clear, then in the forum to ask you prawns bar!

Article from http://www.aspcn.com ASP China Network If you want to reprint please specify the source, thank you

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.