[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Si

7/2/2002 6:17:00 PM

Trying to use ODBC .NET data provider, I succeed in
connecting to my DBMS, but am failing to execute a data
reader. Can someone help with syntax? Thanks.

My stored procedure GET_PERSON has four parameters:
status is an output integer, somid is the only input and
is integer, lname is varchar(35) output, fname is varchar
(35) output.

Private Sub Button3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button3.Click
Dim cn As OdbcConnection
Dim cmd As OdbcCommand
Dim parm As OdbcParameter
Dim drdr As OdbcDataReader
cn = New OdbcConnection("Provider=MSDASQL;DSN=net
Practice;ServerDSN=s1032_net;UID=****;PWD=**********;")
cmd = New OdbcCommand("GET_PERSON", cn)
cmd.CommandType = CommandType.StoredProcedure
parm = cmd.Parameters.Add("@somid", OdbcType.Int)
parm.Value = 1
' also tried the line below alone
'cmd = New OdbcCommand("{call GET_PERSON
(null,1,null,null)}", cn)

cn.Open()
MsgBox("Connected") 'this succeeds
drdr = cmd.ExecuteReader() ' "unhandled exception"
MsgBox("Reader executed")
If drdr.Read() Then
txtfn.Text = drdr.GetString(3)
txtln.Text = drdr.GetString(2)
End If
drdr.Close()
cn.Close()
End Sub

Here's the working asp classic code:

Set oCmd = Server.CreateObject("ADODB.COMMAND")
oCmd.activeconnection=oConn

oCmd.CommandText = "GET_PERSON"
oCmd.CommandType = 4
oCmd(0) = NULL
oCmd(1) = 1
oCmd(2) = NULL
oCmd(3) = NULL
oCmd.Execute("GET_PERSON")
%>
<% Response.Write oCmd(3) & " " & oCmd(2) & "<br>" %>
<%
set oCmd.activeconnection = nothing
set oCmd = nothing
set oConn = nothing
%>
1 Answer

(Steven Bras [MS])

7/2/2002 10:13:00 PM

0

The problem is your connection string; the ODBC managed provider does not
take a "provider=" parameter in its connection string. It's redundant to
specify the Microsoft OLEDB Provider for ODBC Drivers in the ODBC managed
provider, because it in a sense replaces that provider. Once you remove it,
I'll be the error goes away.

Hope this helps!

Steven Bras, MCSD
Microsoft Developer Support/Visual Basic WebData

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.co....