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

sql won't execute HELP!!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have been working on this for a couple of days and I can not get this to work. I need to be able to pull up a report from the sql database into an html table using vbscript. My code is not working. Can anyone see what the problem is??



srtConn = "DRIVER=SQL Server;SERVER=;UID=;PWD=;DATABASE="

Set objDBConn = SERVER.CreateObject("ADODB.Connection")
objDBConn.Open strConn


strCommandText = "SELECT dbo.t_EMPLOYEES.CurrentComp," &_
"dbo.t_EMPLOYEES.LAST_NAME, " &_
"dbo.t_EMPLOYEES.FIRST_NAME, " &_
"dbo.t_EMPLOYEES.STATUS, " &_
"dbo.t_EMPLOYEES.POSITION, " &_
"dbo.t_EMPLOYEES.PROGRAM, " &_
"dbo.t_GOVERNMENT.JOB_SERIES, " &_
"dbo.t_GOVERNMENT.GRADE, " &_
"Left([CurrentComp],3) AS Comp, " &_
"dbo.t_EMPLOYEES.EmployeeID, " &_
"[LAST_NAME]&', '&[FIRST_NAME] AS Name " &_

"FROM dbo.t_EMPLOYEES, dbo.t_GOVERNMENT " &_
"JOIN dbo.t_GOVERNMENT ON dbo.t_EMPLOYEES.EmployeeID = dbo.t_GOVERNMENT.EmployeeID " &_
"GROUP BY dbo.t_EMPLOYEES.CurrentComp, dbo.t_EMPLOYEES.LAST_NAME, dbo.t_EMPLOYEES.FIRST_NAME, " &_
"dbo.t_EMPLOYEES.STATUS, dbo.t_EMPLOYEES.POSITION, dbo.t_EMPLOYEES.PROGRAM, dbo.t_GOVERNMENT.JOB_SERIES, " &_
"dbo.t_GOVERNMENT.GRADE, Left([CurrentComp],3), dbo.t_EMPLOYEES.EmployeeID, [LAST_NAME]&', '&[FIRST_NAME] " &_
"HAVING (((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'VAC%') AND " &_
"((dbo.t_EMPLOYEES.STATUS) Like 'perman%' Or (dbo.t_EMPLOYEES.STATUS) Like '%term%')) " &_
"OR (((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'vac%') AND ((dbo.t_EMPLOYEES.STATUS) Like 'perman%' " &_
" Or (dbo.t_EMPLOYEES.STATUS) Like 'term%')) " &_
"ORDER BY dbo.t_EMPLOYEES.CurrentComp, dbo.t_EMPLOYEES.LAST_NAME "



Set rsEmployee = objDBConn. Execute strCommandText, , _
adCmdText
%>


</head>

<body>

<table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;20%&quot;><%rs(LAST_NAME)%></td>
<td width=&quot;20%&quot;> </td>
<td width=&quot;20%&quot;> </td>
<td width=&quot;20%&quot;> </td>
<td width=&quot;20%&quot;> </td>
</tr>
</table>
</body>

</html>
 
bettyMarkley,

What kind of error are you getting? Are you able to access the database in the first place? You don't have any username or password in your connect statement.


fengshui_1998
 
I took all of that stuff at the top out because I work for the government and they are a little wild about security. But the connection does have a username and password and database.

The exact error message I am getting is this:

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/logistics_dev/lori/lorisAlignment.asp, line 35

Set rsEmployee = objDBConn. Execute strCommandText, , _
------------------------------------^

Thanks for your help in advance..
 
betty,

I think you have an unbalanced parenthesis in this part of the code. It doesn't display very well on this web page but it doesn't look right by glancing at it which is why you're getting &quot;expected end of statement&quot;

fengshui_1998

&quot;HAVING (((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'VAC%') AND &quot; &_
&quot;((dbo.t_EMPLOYEES.STATUS) Like 'perman%' Or (dbo.t_EMPLOYEES.STATUS) Like '%term%')) &quot; &_
&quot;OR (((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'vac%') AND ((dbo.t_EMPLOYEES.STATUS) Like 'perman%' &quot; &_
&quot; Or (dbo.t_EMPLOYEES.STATUS) Like 'term%')) &quot; &_
&quot;ORDER BY dbo.t_EMPLOYEES.CurrentComp, dbo.t_EMPLOYEES.LAST_NAME &quot;



 
I think that i balanced the paren. I am still getting the same error.





&quot;HAVING ((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'VAC%') AND &quot; &_
&quot;((dbo.t_EMPLOYEES.STATUS) Like 'perman%' Or (dbo.t_EMPLOYEES.STATUS) Like '%term%') &quot; &_
&quot;OR ((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'vac%') AND ((dbo.t_EMPLOYEES.STATUS) Like 'perman%') &quot; &_
&quot; Or ((dbo.t_EMPLOYEES.STATUS) Like 'term%') &quot; &_
&quot;ORDER BY dbo.t_EMPLOYEES.CurrentComp, dbo.t_EMPLOYEES.LAST_NAME &quot;



 
It looks like you have a space in here before the Execute:

Set rsEmployee = objDBConn. Execute

Try taking that out and see what happens.
 
I took out the space, still no go. Does my connection string look o.k.? Am I using the execute method correctly?
Should I be using the get method or post method?
 
Have you written out your SQL statement to make sure that everything is OK with that?

Just comment out your Execute line for a minute and Response.write your SQL statement and make sure you are getting what you expect there.
 
I have tried the response.write and I don't see any problems. I have made some changes as follows and now I am getting a new error which is:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

/logistics_dev/lori/lorisAlignment.asp, line 11


the new code is:



<%@ LANGUAGE=&quot;VBSCRIPT&quot;%>
<%Response.Buffer = True%>
<%

Set objDBConn = SERVER.CreateObject(&quot;ADODB.Connection&quot;)

srtConn = &quot;driver=SQLServer;server=cpedis1;UID=makarowskitw;PWD=makarowskitw;database=30_pers&quot;

objDBConn.Open strConn

strCommandText = &quot;SELECT dbo.t_EMPLOYEES.CurrentComp,&quot; &_
&quot;dbo.t_EMPLOYEES.LAST_NAME, &quot; &_
&quot;dbo.t_EMPLOYEES.FIRST_NAME, &quot; &_
&quot;dbo.t_EMPLOYEES.STATUS, &quot; &_
&quot;dbo.t_EMPLOYEES.POSITION, &quot; &_
&quot;dbo.t_EMPLOYEES.PROGRAM, &quot; &_
&quot;dbo.t_GOVERNMENT.JOB_SERIES, &quot; &_
&quot;dbo.t_GOVERNMENT.GRADE, &quot; &_
&quot;Left([CurrentComp],3) AS Comp, &quot; &_
&quot;dbo.t_EMPLOYEES.EmployeeID, &quot; &_
&quot;[LAST_NAME]&', '&[FIRST_NAME] AS Name &quot; &_

&quot;FROM dbo.t_EMPLOYEES, dbo.t_GOVERNMENT &quot; &_
&quot;JOIN dbo.t_GOVERNMENT ON dbo.t_EMPLOYEES.EmployeeID = dbo.t_GOVERNMENT.EmployeeID &quot; &_
&quot;GROUP BY dbo.t_EMPLOYEES.CurrentComp, dbo.t_EMPLOYEES.LAST_NAME, dbo.t_EMPLOYEES.FIRST_NAME, &quot; &_
&quot;dbo.t_EMPLOYEES.STATUS, dbo.t_EMPLOYEES.POSITION, dbo.t_EMPLOYEES.PROGRAM, dbo.t_GOVERNMENT.JOB_SERIES, &quot; &_
&quot;dbo.t_GOVERNMENT.GRADE, Left([CurrentComp],3), dbo.t_EMPLOYEES.EmployeeID, [LAST_NAME]&', '&[FIRST_NAME] &quot; &_
&quot;HAVING ((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'VAC%') AND &quot; &_
&quot;((dbo.t_EMPLOYEES.STATUS) Like 'perman%' Or (dbo.t_EMPLOYEES.STATUS) Like '%term%') &quot; &_
&quot;OR ((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'vac%') AND ((dbo.t_EMPLOYEES.STATUS) Like 'perman%') &quot; &_
&quot; Or ((dbo.t_EMPLOYEES.STATUS) Like 'term%') &quot; &_
&quot;ORDER BY dbo.t_EMPLOYEES.CurrentComp, dbo.t_EMPLOYEES.LAST_NAME &quot;



Set rsEmployee = objDBConn.Execute(strCommandText)
%>


</head>

<body>

<table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;20%&quot;><%rsEmployee(LAST_NAME)%></td>
<td width=&quot;20%&quot;><%rsEmployee(FIRST_NAME)%></td>
<td width=&quot;20%&quot;> </td>
<td width=&quot;20%&quot;> </td>
<td width=&quot;20%&quot;> </td>
</tr>
</table>
</body>





 
I have tried the response.write and I don't see any problems. I have made some changes as follows and now I am getting a new error which is:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

/logistics_dev/lori/lorisAlignment.asp, line 11


the new code is:



<%@ LANGUAGE=&quot;VBSCRIPT&quot;%>
<%Response.Buffer = True%>
<%

Set objDBConn = SERVER.CreateObject(&quot;ADODB.Connection&quot;)

srtConn = &quot;driver=SQLServer;server=cpedis1;UID=makarowskitw;PWD=makarowskitw;database=30_pers&quot;

objDBConn.Open strConn

strCommandText = &quot;SELECT dbo.t_EMPLOYEES.CurrentComp,&quot; &_
&quot;dbo.t_EMPLOYEES.LAST_NAME, &quot; &_
&quot;dbo.t_EMPLOYEES.FIRST_NAME, &quot; &_
&quot;dbo.t_EMPLOYEES.STATUS, &quot; &_
&quot;dbo.t_EMPLOYEES.POSITION, &quot; &_
&quot;dbo.t_EMPLOYEES.PROGRAM, &quot; &_
&quot;dbo.t_GOVERNMENT.JOB_SERIES, &quot; &_
&quot;dbo.t_GOVERNMENT.GRADE, &quot; &_
&quot;Left([CurrentComp],3) AS Comp, &quot; &_
&quot;dbo.t_EMPLOYEES.EmployeeID, &quot; &_
&quot;[LAST_NAME]&', '&[FIRST_NAME] AS Name &quot; &_

&quot;FROM dbo.t_EMPLOYEES, dbo.t_GOVERNMENT &quot; &_
&quot;JOIN dbo.t_GOVERNMENT ON dbo.t_EMPLOYEES.EmployeeID = dbo.t_GOVERNMENT.EmployeeID &quot; &_
&quot;GROUP BY dbo.t_EMPLOYEES.CurrentComp, dbo.t_EMPLOYEES.LAST_NAME, dbo.t_EMPLOYEES.FIRST_NAME, &quot; &_
&quot;dbo.t_EMPLOYEES.STATUS, dbo.t_EMPLOYEES.POSITION, dbo.t_EMPLOYEES.PROGRAM, dbo.t_GOVERNMENT.JOB_SERIES, &quot; &_
&quot;dbo.t_GOVERNMENT.GRADE, Left([CurrentComp],3), dbo.t_EMPLOYEES.EmployeeID, [LAST_NAME]&', '&[FIRST_NAME] &quot; &_
&quot;HAVING ((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'VAC%') AND &quot; &_
&quot;((dbo.t_EMPLOYEES.STATUS) Like 'perman%' Or (dbo.t_EMPLOYEES.STATUS) Like '%term%') &quot; &_
&quot;OR ((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'vac%') AND ((dbo.t_EMPLOYEES.STATUS) Like 'perman%') &quot; &_
&quot; Or ((dbo.t_EMPLOYEES.STATUS) Like 'term%') &quot; &_
&quot;ORDER BY dbo.t_EMPLOYEES.CurrentComp, dbo.t_EMPLOYEES.LAST_NAME &quot;



Set rsEmployee = objDBConn.Execute(strCommandText)
%>


</head>

<body>

<table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;20%&quot;><%rsEmployee(LAST_NAME)%></td>
<td width=&quot;20%&quot;><%rsEmployee(FIRST_NAME)%></td>
<td width=&quot;20%&quot;> </td>
<td width=&quot;20%&quot;> </td>
<td width=&quot;20%&quot;> </td>
</tr>
</table>
</body>





 
I have tried the response.write and I don't see any problems. I have made some changes as follows and now I am getting a new error which is:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

/logistics_dev/lori/lorisAlignment.asp, line 11


the new code is:



<%@ LANGUAGE=&quot;VBSCRIPT&quot;%>
<%Response.Buffer = True%>
<%

Set objDBConn = SERVER.CreateObject(&quot;ADODB.Connection&quot;)

srtConn = &quot;driver=SQLServer;server=cpedis1;UID=makarowskitw;PWD=makarowskitw;database=30_pers&quot;

objDBConn.Open strConn

strCommandText = &quot;SELECT dbo.t_EMPLOYEES.CurrentComp,&quot; &_
&quot;dbo.t_EMPLOYEES.LAST_NAME, &quot; &_
&quot;dbo.t_EMPLOYEES.FIRST_NAME, &quot; &_
&quot;dbo.t_EMPLOYEES.STATUS, &quot; &_
&quot;dbo.t_EMPLOYEES.POSITION, &quot; &_
&quot;dbo.t_EMPLOYEES.PROGRAM, &quot; &_
&quot;dbo.t_GOVERNMENT.JOB_SERIES, &quot; &_
&quot;dbo.t_GOVERNMENT.GRADE, &quot; &_
&quot;Left([CurrentComp],3) AS Comp, &quot; &_
&quot;dbo.t_EMPLOYEES.EmployeeID, &quot; &_
&quot;[LAST_NAME]&', '&[FIRST_NAME] AS Name &quot; &_

&quot;FROM dbo.t_EMPLOYEES, dbo.t_GOVERNMENT &quot; &_
&quot;JOIN dbo.t_GOVERNMENT ON dbo.t_EMPLOYEES.EmployeeID = dbo.t_GOVERNMENT.EmployeeID &quot; &_
&quot;GROUP BY dbo.t_EMPLOYEES.CurrentComp, dbo.t_EMPLOYEES.LAST_NAME, dbo.t_EMPLOYEES.FIRST_NAME, &quot; &_
&quot;dbo.t_EMPLOYEES.STATUS, dbo.t_EMPLOYEES.POSITION, dbo.t_EMPLOYEES.PROGRAM, dbo.t_GOVERNMENT.JOB_SERIES, &quot; &_
&quot;dbo.t_GOVERNMENT.GRADE, Left([CurrentComp],3), dbo.t_EMPLOYEES.EmployeeID, [LAST_NAME]&', '&[FIRST_NAME] &quot; &_
&quot;HAVING ((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'VAC%') AND &quot; &_
&quot;((dbo.t_EMPLOYEES.STATUS) Like 'perman%' Or (dbo.t_EMPLOYEES.STATUS) Like '%term%') &quot; &_
&quot;OR ((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'vac%') AND ((dbo.t_EMPLOYEES.STATUS) Like 'perman%') &quot; &_
&quot; Or ((dbo.t_EMPLOYEES.STATUS) Like 'term%') &quot; &_
&quot;ORDER BY dbo.t_EMPLOYEES.CurrentComp, dbo.t_EMPLOYEES.LAST_NAME &quot;



Set rsEmployee = objDBConn.Execute(strCommandText)
%>


</head>

<body>

<table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;20%&quot;><%rsEmployee(LAST_NAME)%></td>
<td width=&quot;20%&quot;><%rsEmployee(FIRST_NAME)%></td>
<td width=&quot;20%&quot;> </td>
<td width=&quot;20%&quot;> </td>
<td width=&quot;20%&quot;> </td>
</tr>
</table>
</body>





 
bettyMarkley,

Your code needs some changing below

<td width=&quot;20%&quot;><%=rsEmployee(&quot;LAST_NAME&quot;)%></td>
<td width=&quot;20%&quot;><%=rsEmployee(&quot;FIRST_NAME&quot;)%></td>
<td width=&quot;20%&quot;> </td>
<td width=&quot;20%&quot;> </td>
<td width=&quot;20%&quot;> </td>
</tr>
</table>
</body>


fengshui_1998





 
bettyMarkley,

Try using this connection string...

SQL_Svr = &quot;MyServername&quot;
UID = &quot;MyUID&quot;
PASSWORD = &quot;MyPassword&quot;

strConn = &quot;PROVIDER=SQLOLEDB;&quot; & _
&quot;DRIVER={SQL Server};&quot; & _
&quot;SERVER=&quot; & SQL_Svr & &quot;;&quot; & _
&quot;DATABASE=&quot; & DBase & &quot;;&quot; & _
&quot;UID=&quot; & UID & &quot;;&quot; & _
&quot;PWD=&quot; & PASSWORD

fengshui_1998
 
I made some additional changes, and did the correction string the way you said but still no go.



objDBConn.Open strConn
strCommandText=&quot;SELECT dbo.t_EMPLOYEES.CurrentComp,&quot; &_
&quot;dbo.t_EMPLOYEES.LAST_NAME, &quot; &_
&quot;dbo.t_EMPLOYEES.FIRST_NAME, &quot; &_
&quot;dbo.t_EMPLOYEES.STATUS, &quot; &_
&quot;dbo.t_EMPLOYEES.POSITION, &quot; &_
&quot;dbo.t_EMPLOYEES.PROGRAM, &quot; &_
&quot;dbo.t_GOVERNMENT.JOB_SERIES, &quot; &_
&quot;dbo.t_GOVERNMENT.GRADE, &quot; &_
&quot;dbo.t_EMPLOYEES.EmployeeID &quot; &_

&quot;FROM dbo.t_EMPLOYEES, dbo.t_GOVERNMENT &quot; &_
&quot;WHERE dbo.t_EMPLOYEES.EmployeeID = dbo.t_GOVERNMENT.EmployeeID &quot; &_
&quot;GROUP BY dbo.t_EMPLOYEES.CurrentComp, dbo.t_EMPLOYEES.LAST_NAME, dbo.t_EMPLOYEES.FIRST_NAME, &quot; &_
&quot;dbo.t_EMPLOYEES.STATUS, dbo.t_EMPLOYEES.POSITION, dbo.t_EMPLOYEES.PROGRAM, dbo.t_GOVERNMENT.JOB_SERIES, &quot; &_
&quot;dbo.t_GOVERNMENT.GRADE, Left([CurrentComp],3), dbo.t_EMPLOYEES.EmployeeID, [LAST_NAME]&', '&[FIRST_NAME] &quot; &_
&quot;HAVING ((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'VAC%') AND ((dbo.t_EMPLOYEES.LAST_NAME) Not Like 'vac%') &quot; &_
&quot;AND ((dbo.t_EMPLOYEES.STATUS) Like 'perman%' Or (dbo.t_EMPLOYEES.STATUS) Like '%term%')) &quot; &_
&quot;ORDER BY dbo.t_EMPLOYEES.CurrentComp, dbo.t_EMPLOYEES.LAST_NAME &quot;



Set rsEmployee = objDBConn.Execute(strCommandText)
%>


</head>

<body>

<table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;20%&quot;><%rsEmployee(&quot;LAST_NAME&quot;)%></td>
<td width=&quot;20%&quot;><%rsEmployee(&quot;FIRST_NAME&quot;)%></td>
<td width=&quot;20%&quot;>&nbsp;</td>
<td width=&quot;20%&quot;>&nbsp;</td>
<td width=&quot;20%&quot;>&nbsp;</td>
</tr>
</table>
</body>

</html>
 

I am specifically getting an error in this line below.

Set rsEmployee = objDBConn.Execute(strCommandText)
 
bettyMarkley,

I think you need to this one thing at a time.

First see if you have a connection to the database by selecting one simple query and printing out a single value.

This will ensure you have a good connection. If so start adding more to your string query.

strSQL = &quot;SELECT * FROM dbo.t_EMPLOYEES, dbo.t_GOVERNMENT WHERE .... etc

Cheers,
fengshui_1998





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top