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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i connect to database

Status
Not open for further replies.

sim133

Technical User
Sep 14, 2004
85
US
i have an asp written a simple asp code to connect to the database in order to generate some reports. my question would be do i need to fulfil some kind of pre-requiernments for me to pull those data from the databse. eg. do i need to set up ODBC driver ? DNS name....
 
here is another driver

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider = MSDAORA;User ID=myuser;Password=mypwd;Data Source=myserver;DATABASE=mydb;"
Set rs = conn.Execute("SELECT * FROM tblname")

try this see if it works, just replace server,database, username , password
 
sim

help us here;-)

1. what IS the name of your server?
2. what is the name of your db?
3. is the database in same directory as the asp files?

 
He isn't using a file-based database driver so #3 doesn't really matter.
 
also try this (odbc)

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Username;Pwd=asdasd;Database=datasebasename;"
Set rs = conn.Execute("SELECT * FROM tblname")
 
sim...are you getting an error code when trying to connect?
 
Stevens 1st connection statement seems to be the current driver for an oracle9i database.
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider = MSDAORA;User ID=myuser;Password=mypwd;Data Source=myserver;DATABASE=mydb;"
Set rs = conn.Execute("SELECT * FROM tblname")
%>
 
Here is the error msg i got.

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle on SQL_HANDLE_ENV failed

/vendor.asp, line 3

here is my code
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=xyz;Pwd=xyz;Database=tplp;"
Set rs = conn.Execute("SELECT * FROM vendor")

%>
<table border="1" align="center">
<tr>
<% for each oField in testRS.Fields %>
<td><b><%= oField.Name %></b></td>
<%next%>
</tr>
<%do while not testRS.EOF %>
<tr>
<% for each oField in testRS.Fields %>
<td>
<% If IsNull(oField) then
response.write "what is up"
else
response.write oField.Value
end if%>
</td>

<%next
testRS.movenext%>
</tr>
<%loop%>
</table>
<%
testRS.close
set testRS = nothing

%>


 
try theses connection strings

<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider = MSDAORA;User ID=myuser;Password=mypwd;Data Source=myserver;DATABASE=mydb;"
Set rs = conn.Execute("SELECT * FROM tblname")
%>

if it doesn't work try this
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=MSDASQL;DRIVER={Microsoft ODBC for ORACLE};UID=User;PWD=Password;Server=Your_TNSNames_Alias;DATABASE=mydb;"
Set rs = conn.Execute("SELECT * FROM tblname")
%>
 
Guys thank you for the help but i am still not connected to database. It seems a very straight forward process for some reason it is not working for me. I probably,look for someone server admn to take a look at it.
thank you and i appreciate your prompt response and priceless ideas.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top