SQL上的无效转换为其他服务器 [英] Invalid cast on SQL to other server

查看:53
本文介绍了SQL上的无效转换为其他服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对本地MSAccess数据库进行以下调用可以正常工作:

Sub Session_Start(ByVal sender As Object,ByVal e As EventArgs)

Dim intRows作为整数

Dim strSQL As String

Dim ds作为新数据集

''创建连接

Dim cn As新的OleDbConnection

使用cn

.connectionstring =" provider = Microsoft.Jet.OLEDB.4.0;" &安培; _

"数据源= C:\ PDB \Development\Database\PDB.mdb"

结束

' '打开连接

cn.Open()

''------------------------ -----------------------------------

''获取系统名称

''------------------------------------------ -----------------

''创建命令

Dim cmd1 As New OleDbCommand

使用cmd1

.Connection = cn

.CommandText =" SELECT System FROM Reference"

结束

''执行SQL

Dim strSystemName As Integer = cmd1.ExecuteScalar

但是,将连接字符串更改为


.ConnectionString = Provider = MS Remote; &安培; _

" Remote Server = http:// scfmzcp1;" &安培; _

" Remote Provider = Microsoft.Jet.OLEDB.4.0;" &安培; _

数据源= W:\ PDB \Development\PDB.mdb;" &安培; _

连接超时= 30


导致指定演员表无效在ExecuteScalar行上留言。


感谢您的帮助


John

Making the following call to a local MSAccess database works fine:

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim intRows As Integer
Dim strSQL As String
Dim ds As New DataSet
'' Create connection
Dim cn As New OleDbConnection
With cn
.connectionstring = "provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\PDB\Development\Database\PDB.mdb"
End With
'' Open connection
cn.Open()
'' -----------------------------------------------------------
'' Get System Name
'' -----------------------------------------------------------
'' Create command
Dim cmd1 As New OleDbCommand
With cmd1
.Connection = cn
.CommandText = "SELECT System FROM Reference"
End With
'' Execute the SQL
Dim strSystemName As Integer = cmd1.ExecuteScalar
However, changing the connectionstring to

.ConnectionString = "Provider=MS Remote;" & _
"Remote Server=http://scfmzcp1;" & _
"Remote Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=W:\PDB\Development\PDB.mdb;" & _
"Connection Timeout=30"

causes a "Specified cast is not valid" message on the ExecuteScalar line.

Thanks for your help

John

推荐答案

在文章< 40 ******** @ news.hcs.net>中,john @ nowhere说...
In article <40********@news.hcs.net>, john@nowhere says...
对本地MSAccess进行以下调用数据库工作正常:

Sub Session_Start(ByVal sender As Object,ByVal e As EventArgs)
Dim intRows as Integer
Dim strSQL As String
Dim ds As New DataSet
''创建连接
Dim cn As New OleDbConnection
使用cn
.connectionstring =" provider = Microsoft.Jet.OLEDB.4.0;" &安培; _
"数据源= C:\ PDB \Development\Database\PDB.mdb"
结束
''打开连接
cn.Open()
''-------------------------------------------- ---------------
''获取系统名称
''-------------------- ---------------------------------------
''创建命令
Dim cmd1 As New OleDbCommand
cmd1
.Connection = cn
.CommandText =" SELECT System FROM Reference"
结束
''执行SQL
Dim strSystemName As Integer = cmd1.ExecuteScalar

但是,将连接字符串更改为

.ConnectionString =" Provider = MS Remote;" &安培; _
远程服务器= http:// scfmzcp1;" &安培; _
Remote Provider = Microsoft.Jet.OLEDB.4.0;" &安培; _
数据源= W:\ PDB \Development\PDB.mdb;" &安培; _
连接超时= 30

导致指定演员阵容无效在ExecuteScalar行上的消息。
Making the following call to a local MSAccess database works fine:

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim intRows As Integer
Dim strSQL As String
Dim ds As New DataSet
'' Create connection
Dim cn As New OleDbConnection
With cn
.connectionstring = "provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\PDB\Development\Database\PDB.mdb"
End With
'' Open connection
cn.Open()
'' -----------------------------------------------------------
'' Get System Name
'' -----------------------------------------------------------
'' Create command
Dim cmd1 As New OleDbCommand
With cmd1
.Connection = cn
.CommandText = "SELECT System FROM Reference"
End With
'' Execute the SQL
Dim strSystemName As Integer = cmd1.ExecuteScalar
However, changing the connectionstring to

.ConnectionString = "Provider=MS Remote;" & _
"Remote Server=http://scfmzcp1;" & _
"Remote Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=W:\PDB\Development\PDB.mdb;" & _
"Connection Timeout=30"

causes a "Specified cast is not valid" message on the ExecuteScalar line.




要调试,请将行更改为:


dim temp as Object = cmd1.ExecuteScalar


看看temp是什么在调试窗口中。这显然是一些不能被投入整数的东西。


-

Patrick Steele

Microsoft .NET MVP
http://weblogs.asp .net / psteele


嗨约翰


除了帕特里克建议我会使用

SqlDataReader用于保存select命令的结果

因为它可能会返回几行。


亲切的问候

Jorge
Hi John

In addition to what Patrick suggested i would use a
SqlDataReader to hold the result of your select command
since its possible that it is returning several rows.

Kind Regards
Jorge
-----原始消息-----
对本地MSAccess数据库进行以下调用
工作正常:
Sub Session_Start(ByVal sender As Object,ByVal e As
EventArgs)Dim intRows as Integer
Dim strSQL As String
Dim ds As New DataSet
''创建连接
Dim cn作为新的OleDbConnection
与cn
.co nnectionstring
=" provider = Microsoft.Jet.OLEDB.4.0;" &安培; _" Data
Source = C:\ PDB \Development\Database\PDB.mdb"结束
''打开连接
cn.Open()
''------------------------- ----------------------
------------''获取系统名称
'' - ----------------------------------------------
------------''创建命令
Dim cmd1 As New OleDbCommand
cmd1
.Connection = cn
.CommandText =" SELECT System FROM Reference"
结束
''执行SQL
Dim strSystemName As Integer = cmd1.ExecuteScalar

但是,将连接字符串更改为

.ConnectionString =" Provider = MS Remote;" &安培;
_" Remote Server = http:// scfmzcp1;" &安培; _
" Remote
Provider = Microsoft.Jet.OLEDB.4.0;" &安培; _" Data
Source = W:\ PDB \Development\PDB.mdb;" &安培; _连接超时= 30

导致指定演员表无效
ExecuteScalar行的消息。
感谢您的帮助


-----Original Message-----
Making the following call to a local MSAccess database works fine:
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer
Dim strSQL As String
Dim ds As New DataSet
'' Create connection
Dim cn As New OleDbConnection
With cn
.connectionstring = "provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=C:\PDB\Development\Database\PDB.mdb" End With
'' Open connection
cn.Open()
'' ----------------------------------------------- ------------ '' Get System Name
'' ----------------------------------------------- ------------ '' Create command
Dim cmd1 As New OleDbCommand
With cmd1
.Connection = cn
.CommandText = "SELECT System FROM Reference"
End With
'' Execute the SQL
Dim strSystemName As Integer = cmd1.ExecuteScalar
However, changing the connectionstring to

.ConnectionString = "Provider=MS Remote;" & _ "Remote Server=http://scfmzcp1;" & _
"Remote Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=W:\PDB\Development\PDB.mdb;" & _ "Connection Timeout=30"

causes a "Specified cast is not valid" message on the ExecuteScalar line.
Thanks for your help

John
.



SP是否返回任何值?

也许你在sp中有CAST


Gerasha


John Howard <约翰@无处>在留言新闻中写道:40 ****** @ news.hcs.net ...
Is SP return any value?
Maybe you have CAST in sp???

Gerasha

"John Howard" <john@nowhere> wrote in message news:40******@news.hcs.net...
Dim dr As OleDbDataReader = cmd1.ExecuteReader

同样的错误

John Howard <约翰@无处>在消息中写道
Dim dr As OleDbDataReader = cmd1.ExecuteReader

Same error

"John Howard" <john@nowhere> wrote in message



news:40 ****** @ news.hcs.net ...


news:40******@news.hcs.net...

这个表只有一行。

Jorge <一个******* @ discussions.microsoft.com>在消息中写道
新闻:19 ***************************** @ phx.gbl ...
This table has only one row.

"Jorge" <an*******@discussions.microsoft.com> wrote in message
news:19*****************************@phx.gbl...
嗨约翰

除了帕特里克建议我将使用一个
SqlDataReader来保存你的选择命令的结果
因为它可能会返回几行。

亲切的问候
Jorge
> -----原始消息-----
>对本地MSAccess数据库进行以下调用
工作正常:
>
> Sub Session_Start(ByVal sender As Object,ByVal e As
EventArgs)
>昏暗的intRows作为整数
> Dim strSQL As String
> Dim ds作为新数据集
> ''创建连接
> Dim cn As New OleDbConnection
>用cn
> .connectionstring
=" provider = Microsoft.Jet.OLEDB.4.0;" &安培; _
> 数据
Source = C:\ PDB \Development\Database\PDB.mdb"
>结束
> ''开放连接
> cn.Open()
> ''-----------------------------------------------
------------
> ''获取系统名称
> ''-----------------------------------------------
------------
> ''创建命令
>昏暗的cmd1作为新的OleDbCommand
>用cmd1
> .Connection = cn
> .CommandText =" SELECT System FROM Reference"
>结束
> ''执行SQL
> Dim strSystemName As Integer = cmd1.ExecuteScalar
>
>
>但是,将连接字符串更改为
>
> .ConnectionString =" Provider = MS Remote;" &
_
> Remote Server = http:// scfmzcp1;" &安培; _
> Remote
Provider = Microsoft.Jet.OLEDB.4.0;" &安培; _
> Data
Source = W:\ PDB \Development\PDB.mdb;" &安培; _
> 连接超时= 30
>
>导致指定演员表无效
ExecuteScalar行上的消息。
>
>感谢您的帮助
>
> John
>
> ;
>。
>
Hi John

In addition to what Patrick suggested i would use a
SqlDataReader to hold the result of your select command
since its possible that it is returning several rows.

Kind Regards
Jorge
>-----Original Message-----
>Making the following call to a local MSAccess database
works fine:
>
> Sub Session_Start(ByVal sender As Object, ByVal e As
EventArgs)
> Dim intRows As Integer
> Dim strSQL As String
> Dim ds As New DataSet
> '' Create connection
> Dim cn As New OleDbConnection
> With cn
> .connectionstring
= "provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data
Source=C:\PDB\Development\Database\PDB.mdb"
> End With
> '' Open connection
> cn.Open()
> '' -----------------------------------------------
------------
> '' Get System Name
> '' -----------------------------------------------
------------
> '' Create command
> Dim cmd1 As New OleDbCommand
> With cmd1
> .Connection = cn
> .CommandText = "SELECT System FROM Reference"
> End With
> '' Execute the SQL
> Dim strSystemName As Integer = cmd1.ExecuteScalar
>
>
>However, changing the connectionstring to
>
> .ConnectionString = "Provider=MS Remote;" &
_
> "Remote Server=http://scfmzcp1;" & _
> "Remote
Provider=Microsoft.Jet.OLEDB.4.0;" & _
> "Data
Source=W:\PDB\Development\PDB.mdb;" & _
> "Connection Timeout=30"
>
>causes a "Specified cast is not valid" message on the
ExecuteScalar line.
>
>Thanks for your help
>
>John
>
>
>.
>





这篇关于SQL上的无效转换为其他服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆