PDA

View Full Version : ASP and Database Connect/RS Problems


Jim_Moten
04-09-2003, 03:03 PM
I recently inherited a database developed by someone with complete disregard for SQL syntax....Trying to connect to Db and obtain schema. Using the following code with no recordset being returned...Connection appears to be working, forced to use DSN-less because, well you'll see why.
Dim oConn
Set oConn = Server.CreateObject("ADODB.Connection")

'oConn.Properties("Prompt") = adPromptAlways
oConn.ConnectionString = "Driver={SQL Server};"
oConn.ConnectionString = oConn.ConnectionString & "Server=sqlserver;Database=Plant;"
oConn.ConnectionString = oConn.ConnectionString & "Trusted_Connection=no;uid=cr_reader;pwd=cr"
oConn.Open

Dim oRS,sqlText
Set oRS = Server.CreateObject("ADODB.Connection")
sqlText = "SELECT * FROM plant_schedule;"
oRS.Open sqlText, "DSN=Plant"
'oRS.Open "SELECT CUSTOMER FROM dbo_**plant_schedule**;" too long?

Response.Write "<table border='1'>"
Do while NOT oRS.EOF
Response.Write "<tr><td>" & oRS("customer") & "&nbsp</td></tr>"
oRS.MoveNext
Loop
Response.Write "</table>"
oRS.Close
Set oRS = Nothing
Response.Expires = 0

Errors rec'd where indicated and why...Here is syntax that executes in SQL Analyzer:
SELECT
A__plant_schedule___."jobnum", A__plant_schedule___."customer", A__plant_schedule___."prs"
FROM
"Plant"."dbo"."** plant_schedule **" A__plant_schedule___

Somebody please help me return a recordset.

raf
04-09-2003, 07:24 PM
Try replacing this

Bad code !!
sqlText = "SELECT * FROM plant_schedule; "
oRS.Open sqlText, "DSN=Plant"
'oRS.Open "SELECT CUSTOMER FROM dbo_**plant_schedule**;" too long?


with this


sqlText = "SELECT * FROM plant_schedule"
oRS.Open sqlText, oConn

Jim_Moten
04-09-2003, 07:28 PM
Thanks a lot, I'll try it. This is a nightmare.

raf
04-09-2003, 07:39 PM
No. It's a learnig opportunity :)

Keep calm (almost the most important thing you need to learn as a coder):D