返回Web服务中的数据库查询结果 [英] returning results of a database query in a web service
问题描述
我在Windows应用程序中编写了这段代码并且它可以工作:
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As
System .EventArgs)处理Button1.Click
Dim ds作为新数据集
将myDbConnection调暗为新的OdbcConnection(" Driver = {Microsoft
Visual FoxPro Driver};"& _
" SourceType = DBF;"& _
" SourceDB = i:\\ \\ probill \;"& _
" Exclusive = No;"& _
" Collate = Machine;"& _
" NULL = NO;"& _
" DELETED = NO;"& _
" BACKGROUNDFETCH = YES" )
Dim mydbcommand As New OdbcCommand(从act_frau中选择标志
where act =''" + TextBox1.Text.Trim +"''", myDbConnection)
myDbConnection.Open()
Dim results As String = mydbcommand.ExecuteScalar()
myDbConnection.Close()
MessageBox.Show(results)
End Sub
那么为什么这不起作用:
< WebMethod()_
公共函数CashOnly(ByVal act String)As String
Dim ds As New DataSet
Dim myOdbcConnection As New OdbcConnection(" ; Driver = {Microsoft
Visual FoxPro Driver};" + _
" SourceType = DBF;" + _
SourceDB = i:\ probbill \;" + _
" Exclusive = No;" + _
" Collate = Machine;" + _
" NULL = NO;" + _
" DELETED = NO;" + _
" BACKGROUNDFETCH = YES")
Dim myOdbcCommand As New OdbcCommand(从act_frau中选择标志
where act =''" + act.Trim +"''",myOdbcConnection)
myOdbcConnection.Open()
Dim results As String = myOdbcCommand.ExecuteScalar()
myOdbcConnection.Close()
返回结果
结束功能
我得到:
System.Data.Odbc.OdbcException:ERROR [42S02] [Microsoft] [ODBC Visual
FoxPro驱动程序]文件' 'act_frau.dbf''不存在。
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHa ndle hrHandle,
RetCode retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior
behavior,String method,Boolean needReader,Object [] methodArguments,
SQL_API odbcApiMethod)
在System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior
behavior,String method,Boolean needReader)
at System.Data.Odbc.OdbcCommand.ExecuteScalar()
at TestWebService1.PaymentService1.CashOnly(String act)in
C:\Documents and Settings\cj\My Documents\Visual Studio
2008 \Projects\TestWebService1\TestWebService1 \ Paym entService1.asmx .vb:line
47
cj,
也许是odbc驱动程序不在服务器上,但为什么你在服务器上使用这个
不完整的提供程序。
因为我是你,我会访问FoxPro新闻组。我知道有更多可靠的解决方案,而且他们知道它。
就像我解决问题的方式一样。
>
Cor
" cj" < cj@nospam.nospamschreef in bericht
news:eT ************** @ TK2MSFTNGP06.phx.gbl ...
>我在Windows应用程序中编写了这段代码,它可以工作:
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button1.Click
Dim ds作为新数据集
将myDbConnection调暗为新的OdbcConnection(" Driver = {Microsoft Visual
FoxPro Driver};"& _
" SourceType = DBF;"& _
SourceDB = i:\ probill \;"& _
" Exclusive = No;"& _
" Collate = Machine ;"& _
" NULL = NO;"& _
" DELETED = NO;" &安培; _
" BACKGROUNDFETCH = YES")
Dim mydbcommand As New OdbcCommand(从act_frau选择标志
where act =''" ; + TextBox1.Text.Trim +"''",myDbConnection)
myDbConnection.Open()
Dim results As String = mydbcommand.ExecuteScalar()
myDbConnection.Close()
MessageBox.Show(results)
End Sub
那么为什么呢这个工作:
< WebMethod()_
公共函数CashOnly(ByVal act String)As String
Dim ds作为新数据集
将myOdbcConnection调暗为新的OdbcConnection(" Driver = {Microsoft
Visual FoxPro Driver};" + _
" SourceType = DBF;" + _
" SourceDB = i:\ probbill \;" + _
" Exclusive = No;" + _
" Collate = Machine;" + _
" NULL = NO;" + _
" DELETED = NO;" + _
" BACKGROUNDFETCH = YES")
Dim myOdbcCommand As New OdbcCommand(从act_frau中选择标志
where act =''" + act.Trim +"''",myOdbcConnection)
myOdbcConnection.Open()
Dim results As String = myOdbcCommand.ExecuteScalar()
myOdbcConnection.Close()
返回结果
结束功能
我得到:
System.Data.Odbc.OdbcException:ERROR [42S02] [Microsoft] [ODBC Visual
FoxPro驱动程序]文件' 'act_frau.dbf''不存在。
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHa ndle hrHandle,
RetCode retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior
behavior,String method,Boolean needReader,Object [] methodArguments,
SQL_API odbcApiMethod)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior
behavior,String method,Boolean needReader)
at System.Data.Odbc.OdbcCommand.ExecuteScalar( )
在TestWebService1.PaymentService1.CashOnly(String act)中的C:\Documents
和Settings\cj\My Documents \ Visual Studio >
2008 \Projects\TestWebService1\TestWebService1\Paym entService1.asmx.vb:line
47
< blockquote> 2008年6月24日星期二14:37:56 -0400,cj< cj@nospam.nospamwrote:
$ b $b¤为什么这不起作用:
$ b $b¤
$ b $b¤< WebMethod()_
$ b $b¤公共功能CashOnly(ByVal act String)As String
$ b $b¤Dim ds作为新数据集
$ b $b¤将myOdbcConnection调暗为新的OdbcConnection(Driver = {Microsoft
$ b $b¤VisualFoxPro Driver};" + _
$ b $b¤" SourceType = DBF;" + _
$ b $b¤SourceDB = i:\ probbill \;" + _
$ b $b¤" Exclusive = No;" + _
$ b $b¤" Collate = Machine;" + _
$ b $b¤" NULL = NO;" + _
$ b $b¤" DELETED = NO;" + _
$ b $b¤" BACKGROUNDFETCH = YES")
$ b $b¤
$ b $b¤将myOdbc命令调暗为新的OdbcCommand(从act_frau中选择标志
$ b $b¤其中act =''" + act.Trim +"''",myOdbcConnection)
$ b $b¤
$ b $b¤myOdbcConnection.Open( )
$ b $b¤昏暗的结果As String = myOdbcCommand.ExecuteScalar()
$ b $b¤myOdbcConnection.Close()
$ b $b¤
¤返回结果
$ b $b¤结束功能
$ b $b¤
$ b $b¤我得到:
$ b $b¤
$ b $b¤System.Data.Odbc.OdbcException:错误[42S02] [Microsoft] [ODBC Visual
$ b $b¤FoxPro驱动程序]文件''act_frau.dbf''不存在。
在System.Data.Odbc.Odbc.OdbcCommand的System.Data.Odbc.OdbcConnection.HandleError(OdbcHa ndle hrHandle,
$ b $b¤RetCoderetcode)上$ b $b¤
$ b $b¤。 ExecuteReaderObject(C ommandBehavior
$ b $b¤行为,String me thod,Boolean needReader,Object [] methodArguments,
ehavior,String method,Boolean needReader)
$ b $b¤at System.Data.Odbc.OdbcCommand.ExecuteScalar()
$ b $b¤在TestWebService1.PaymentService1.CashOnly(String act )
$ b $b¤C:\文档和设置\cj \ Myy文件\ Visual Studio $ $ $ $ $ $ 2008 @\\Projects \ TestWebService1 \ TestWebService1 \ Paym entService1.asmx.vb:line
$ b $b¤47
i驱动器在哪里?这是一个映射到网络资源的驱动器号,还是一个本地驱动器?
Web服务器?
Paul
~~~~
Microsoft MVP(Visual Basic)
i:是一个网络驱动器。我正在使用i:在第一个有效的例子中。
我不明白为什么代码可以在按钮点击
windows应用程序时工作而不是我的网络服务的一部分。我正在向本地主机发布网站
服务。
Paul Clement写道:
2008年6月24日星期二14:37:56 -0400,cj< cj@nospam.nospamwrote:
$ b $b¤为什么这不起作用:
$ b $b¤
$ b $b¤< WebMethod()_
$ b $b¤公共功能CashOnly(ByVal act String)As String
$ b $b¤Dimds作为新数据集
$ b $b¤将myOdbcConnection调暗为新的OdbcConnection(Driver = {Microsoft
$ b $b¤VisualFoxPro Driver};" + _
¤SourceType = DBF;" + _
$ b $b¤SourceDB = i:\ probill \;" + _
$ b $b¤" Exclusive = No ;" + _
$ b $b¤" Collate = Machine;" + _
$ b $b¤" NULL = NO;" + _
¤ " DELETED = NO;" + _
$ b $b¤" BACKGROUNDFETCH = YES")
$ b $b¤
$ b $b¤将myOdbc命令调暗为新的OdbcCommand(从act_frau中选择标志
$ b $b¤其中act =''" + act.Trim +"''",myOdbcConnection)
$ b $b¤
$ b $b¤myOdbcConnection.Open( )
$ b $b¤昏暗的结果As String = myOdbcCommand.ExecuteScalar()
$ b $b¤myOdbcConnection.Close()
$ b $b¤
¤返回结果
$ b $b¤结束功能
$ b $b¤
$ b $b¤我得到:
$ b $b¤
$ b $b¤System.Data.Odbc.OdbcException:错误[42S02] [Microsoft] [ODBC Visual
$ b $b¤FoxPro驱动程序]文件''act_frau.dbf''不存在。
在System.Data.Odbc.Odbc.OdbcCommand的System.Data.Odbc.OdbcConnection.HandleError(OdbcHa ndle hrHandle,
$ b $b¤RetCoderetcode)上$ b $b¤
$ b $b¤。 ExecuteReaderObject(C ommandBehavior
$ b $b¤行为,String me thod,Boolean needReader,Object [] methodArguments,
ehavior,String method,Boolean needReader)
$ b $b¤at System.Data.Odbc.OdbcCommand.ExecuteScalar()
$ b $b¤在TestWebService1.PaymentService1.CashOnly(String act )
$ b $b¤C:\文档和设置\cj \ Myy文件\ Visual Studio $ $ $ $ $ $ 2008 @\\Projects \ TestWebService1 \ TestWebService1 \ Paym entService1.asmx.vb:line
$ b $b¤47
i驱动器在哪里?这是一个映射到网络资源的驱动器号,还是一个本地驱动器?
Web服务器?
Paul
~~~~
Microsoft MVP(Visual Basic)
I wrote this code in a windows app and it works:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ds As New DataSet
Dim myDbConnection As New OdbcConnection("Driver={Microsoft
Visual FoxPro Driver};" & _
"SourceType=DBF;" & _
"SourceDB=i:\probill\;" & _
"Exclusive=No;" & _
"Collate=Machine;" & _
"NULL=NO;" & _
"DELETED=NO;" & _
"BACKGROUNDFETCH=YES")
Dim mydbcommand As New OdbcCommand("select flag from act_frau
where act = ''" + TextBox1.Text.Trim + "''", myDbConnection)
myDbConnection.Open()
Dim results As String = mydbcommand.ExecuteScalar()
myDbConnection.Close()
MessageBox.Show(results)
End Sub
So why doesn''t this work:
<WebMethod()_
Public Function CashOnly(ByVal act String) As String
Dim ds As New DataSet
Dim myOdbcConnection As New OdbcConnection("Driver={Microsoft
Visual FoxPro Driver};" + _
"SourceType=DBF;" + _
"SourceDB=i:\probill\;" + _
"Exclusive=No;" + _
"Collate=Machine;" + _
"NULL=NO;" + _
"DELETED=NO;" + _
"BACKGROUNDFETCH=YES")
Dim myOdbcCommand As New OdbcCommand("select flag from act_frau
where act = ''" + act.Trim + "''", myOdbcConnection)
myOdbcConnection.Open()
Dim results As String = myOdbcCommand.ExecuteScalar()
myOdbcConnection.Close()
Return results
End Function
I get:
System.Data.Odbc.OdbcException: ERROR [42S02] [Microsoft][ODBC Visual
FoxPro Driver]File ''act_frau.dbf'' does not exist.
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHa ndle hrHandle,
RetCode retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior
behavior, String method, Boolean needReader, Object[] methodArguments,
SQL_API odbcApiMethod)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior
behavior, String method, Boolean needReader)
at System.Data.Odbc.OdbcCommand.ExecuteScalar()
at TestWebService1.PaymentService1.CashOnly(String act) in
C:\Documents and Settings\cj\My Documents\Visual Studio
2008\Projects\TestWebService1\TestWebService1\Paym entService1.asmx.vb:line
47
cj,
maybe the odbc driver is not on the server, but why are you using this
incomplete provider on a server.
As I was you I would visit the FoxPro newsgroup. I know that there are much
more reliable solutions and they know it.
Just the way I would solve your problem.
Cor
"cj" <cj@nospam.nospamschreef in bericht
news:eT**************@TK2MSFTNGP06.phx.gbl...>I wrote this code in a windows app and it works:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ds As New DataSet
Dim myDbConnection As New OdbcConnection("Driver={Microsoft Visual
FoxPro Driver};" & _
"SourceType=DBF;" & _
"SourceDB=i:\probill\;" & _
"Exclusive=No;" & _
"Collate=Machine;" & _
"NULL=NO;" & _
"DELETED=NO;" & _
"BACKGROUNDFETCH=YES")
Dim mydbcommand As New OdbcCommand("select flag from act_frau
where act = ''" + TextBox1.Text.Trim + "''", myDbConnection)
myDbConnection.Open()
Dim results As String = mydbcommand.ExecuteScalar()
myDbConnection.Close()
MessageBox.Show(results)
End Sub
So why doesn''t this work:
<WebMethod()_
Public Function CashOnly(ByVal act String) As String
Dim ds As New DataSet
Dim myOdbcConnection As New OdbcConnection("Driver={Microsoft
Visual FoxPro Driver};" + _
"SourceType=DBF;" + _
"SourceDB=i:\probill\;" + _
"Exclusive=No;" + _
"Collate=Machine;" + _
"NULL=NO;" + _
"DELETED=NO;" + _
"BACKGROUNDFETCH=YES")
Dim myOdbcCommand As New OdbcCommand("select flag from act_frau
where act = ''" + act.Trim + "''", myOdbcConnection)
myOdbcConnection.Open()
Dim results As String = myOdbcCommand.ExecuteScalar()
myOdbcConnection.Close()
Return results
End Function
I get:
System.Data.Odbc.OdbcException: ERROR [42S02] [Microsoft][ODBC Visual
FoxPro Driver]File ''act_frau.dbf'' does not exist.
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHa ndle hrHandle,
RetCode retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior
behavior, String method, Boolean needReader, Object[] methodArguments,
SQL_API odbcApiMethod)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior
behavior, String method, Boolean needReader)
at System.Data.Odbc.OdbcCommand.ExecuteScalar()
at TestWebService1.PaymentService1.CashOnly(String act) in C:\Documents
and Settings\cj\My Documents\Visual Studio
2008\Projects\TestWebService1\TestWebService1\Paym entService1.asmx.vb:line
47
On Tue, 24 Jun 2008 14:37:56 -0400, cj <cj@nospam.nospamwrote:
¤ So why doesn''t this work:
¤
¤ <WebMethod()_
¤ Public Function CashOnly(ByVal act String) As String
¤ Dim ds As New DataSet
¤ Dim myOdbcConnection As New OdbcConnection("Driver={Microsoft
¤ Visual FoxPro Driver};" + _
¤ "SourceType=DBF;" + _
¤ "SourceDB=i:\probill\;" + _
¤ "Exclusive=No;" + _
¤ "Collate=Machine;" + _
¤ "NULL=NO;" + _
¤ "DELETED=NO;" + _
¤ "BACKGROUNDFETCH=YES")
¤
¤ Dim myOdbcCommand As New OdbcCommand("select flag from act_frau
¤ where act = ''" + act.Trim + "''", myOdbcConnection)
¤
¤ myOdbcConnection.Open()
¤ Dim results As String = myOdbcCommand.ExecuteScalar()
¤ myOdbcConnection.Close()
¤
¤ Return results
¤ End Function
¤
¤ I get:
¤
¤ System.Data.Odbc.OdbcException: ERROR [42S02] [Microsoft][ODBC Visual
¤ FoxPro Driver]File ''act_frau.dbf'' does not exist.
¤ at System.Data.Odbc.OdbcConnection.HandleError(OdbcHa ndle hrHandle,
¤ RetCode retcode)
¤ at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior
¤ behavior, String method, Boolean needReader, Object[] methodArguments,
¤ SQL_API odbcApiMethod)
¤ at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior
¤ behavior, String method, Boolean needReader)
¤ at System.Data.Odbc.OdbcCommand.ExecuteScalar()
¤ at TestWebService1.PaymentService1.CashOnly(String act) in
¤ C:\Documents and Settings\cj\My Documents\Visual Studio
¤ 2008\Projects\TestWebService1\TestWebService1\Paym entService1.asmx.vb:line
¤ 47
Where is the i drive? Is this a mapped drive letter to a network resource or is it a drive local to
the web server?
Paul
~~~~
Microsoft MVP (Visual Basic)
i: is a network drive. I was using i: in the first example that worked.
I don''t understand why that code will work in the button click of a
windows app and not as part of my web service. I''m publishing the web
service to localhost.
Paul Clement wrote:On Tue, 24 Jun 2008 14:37:56 -0400, cj <cj@nospam.nospamwrote:
¤ So why doesn''t this work:
¤
¤ <WebMethod()_
¤ Public Function CashOnly(ByVal act String) As String
¤ Dim ds As New DataSet
¤ Dim myOdbcConnection As New OdbcConnection("Driver={Microsoft
¤ Visual FoxPro Driver};" + _
¤ "SourceType=DBF;" + _
¤ "SourceDB=i:\probill\;" + _
¤ "Exclusive=No;" + _
¤ "Collate=Machine;" + _
¤ "NULL=NO;" + _
¤ "DELETED=NO;" + _
¤ "BACKGROUNDFETCH=YES")
¤
¤ Dim myOdbcCommand As New OdbcCommand("select flag from act_frau
¤ where act = ''" + act.Trim + "''", myOdbcConnection)
¤
¤ myOdbcConnection.Open()
¤ Dim results As String = myOdbcCommand.ExecuteScalar()
¤ myOdbcConnection.Close()
¤
¤ Return results
¤ End Function
¤
¤ I get:
¤
¤ System.Data.Odbc.OdbcException: ERROR [42S02] [Microsoft][ODBC Visual
¤ FoxPro Driver]File ''act_frau.dbf'' does not exist.
¤ at System.Data.Odbc.OdbcConnection.HandleError(OdbcHa ndle hrHandle,
¤ RetCode retcode)
¤ at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior
¤ behavior, String method, Boolean needReader, Object[] methodArguments,
¤ SQL_API odbcApiMethod)
¤ at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(C ommandBehavior
¤ behavior, String method, Boolean needReader)
¤ at System.Data.Odbc.OdbcCommand.ExecuteScalar()
¤ at TestWebService1.PaymentService1.CashOnly(String act) in
¤ C:\Documents and Settings\cj\My Documents\Visual Studio
¤ 2008\Projects\TestWebService1\TestWebService1\Paym entService1.asmx.vb:line
¤ 47
Where is the i drive? Is this a mapped drive letter to a network resource or is it a drive local to
the web server?
Paul
~~~~
Microsoft MVP (Visual Basic)
这篇关于返回Web服务中的数据库查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!