473,545 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Invalid cast on SQL to other server

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

Sub Session_Start(B yVal 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
.connectionstri ng = "provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=C:\PDB\D evelopment\Data base\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.ExecuteSca lar
However, changing the connectionstrin g to

.ConnectionStri ng = "Provider=M S Remote;" & _
"Remote Server=http://scfmzcp1;" & _
"Remote Provider=Micros oft.Jet.OLEDB.4 .0;" & _
"Data Source=W:\PDB\D evelopment\PDB. mdb;" & _
"Connection Timeout=30"

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

Thanks for your help

John
Nov 20 '05 #1
21 1897
In article <40********@new s.hcs.net>, john@nowhere says...
Making the following call to a local MSAccess database works fine:

Sub Session_Start(B yVal 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
.connectionstri ng = "provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=C:\PDB\D evelopment\Data base\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.ExecuteSca lar
However, changing the connectionstrin g to

.ConnectionStri ng = "Provider=M S Remote;" & _
"Remote Server=http://scfmzcp1;" & _
"Remote Provider=Micros oft.Jet.OLEDB.4 .0;" & _
"Data Source=W:\PDB\D evelopment\PDB. mdb;" & _
"Connection Timeout=30"

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


To debug, change the line to:

dim temp as Object = cmd1.ExecuteSca lar

And see what "temp" is in the debug window. It's obviously something
that can't be cast to an Integer.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #2
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(B yVal 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
.connectionstri ng = "provider=Micro soft.Jet.OLEDB. 4.0;" & _ "Data Source=C:\PDB\D evelopment\Data base\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.ExecuteSca lar
However, changing the connectionstrin g to

.ConnectionStri ng = "Provider=M S Remote;" & _ "Remote Server=http://scfmzcp1;" & _
"Remote Provider=Micros oft.Jet.OLEDB.4 .0;" & _ "Data Source=W:\PDB\D evelopment\PDB. mdb;" & _ "Connection Timeout=30"

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

John
.

Nov 20 '05 #3
Is SP return any value?
Maybe you have CAST in sp???

Gerasha

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

Same error

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

news:40******@n ews.hcs.net...
This table has only one row.

"Jorge" <an*******@disc ussions.microso ft.com> wrote in message
news:19******** *************** ******@phx.gbl. ..
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(B yVal 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
> .connectionstri ng
= "provider=Micro soft.Jet.OLEDB. 4.0;" & _
> "Data
Source=C:\PDB\D evelopment\Data base\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.ExecuteSca lar
>
>
>However, changing the connectionstrin g to
>
> .ConnectionStri ng = "Provider=M S Remote;" &
_
> "Remote Server=http://scfmzcp1;" & _
> "Remote
Provider=Micros oft.Jet.OLEDB.4 .0;" & _
> "Data
Source=W:\PDB\D evelopment\PDB. mdb;" & _
> "Connection Timeout=30"
>
>causes a "Specified cast is not valid" message on the
ExecuteScalar line.
>
>Thanks for your help
>
>John
>
>
>.
>



Nov 20 '05 #4
In article <40********@new s.hcs.net>, john@nowhere says...
Dim temp As Object = cmd1.ExecuteSca lar

Amazing - this gives the same error.


Very odd... Does the Exception that is thrown contain anything in the
"InnerException " property? There's got to be a stack trace somewhere
showing exactly what is throwing the invalid cast exception.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #5
I don't understand

"Herman Kheyfets" <we***@gerasha. com> wrote in message
news:uC******** ******@TK2MSFTN GP11.phx.gbl...
Is SP return any value?
Maybe you have CAST in sp???

Gerasha

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

news:40******@n ews.hcs.net...
Dim dr As OleDbDataReader = cmd1.ExecuteRea der

Same error

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

news:40******@n ews.hcs.net...
This table has only one row.

"Jorge" <an*******@disc ussions.microso ft.com> wrote in message
news:19******** *************** ******@phx.gbl. ..
> 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(B yVal 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
> > .connectionstri ng
> = "provider=Micro soft.Jet.OLEDB. 4.0;" & _
> > "Data
> Source=C:\PDB\D evelopment\Data base\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.ExecuteSca lar
> >
> >
> >However, changing the connectionstrin g to
> >
> > .ConnectionStri ng = "Provider=M S Remote;" &
> _
> > "Remote Server=http://scfmzcp1;" & _
> > "Remote
> Provider=Micros oft.Jet.OLEDB.4 .0;" & _
> > "Data
> Source=W:\PDB\D evelopment\PDB. mdb;" & _
> > "Connection Timeout=30"
> >
> >causes a "Specified cast is not valid" message on the
> ExecuteScalar line.
> >
> >Thanks for your help
> >
> >John
> >
> >
> >.
> >



Nov 20 '05 #6
Here is the result. I can't make any sense of it:

Line 71: ' Execute the SQL
Line 72: 'Dim dr As OleDbDataReader = cmd1.ExecuteRea der
Line 73: Dim temp As Object = cmd1.ExecuteSca lar
Line 74: Dim strSystemName As Integer
Line 75: 'Dim strSystemName As Integer = cmd1.ExecuteSca lar
Source File: C:\Inetpub\wwwr oot\WebPDB2\Glo bal.asax.vb Line: 73

Stack Trace:

[InvalidCastExce ption: Specified cast is not valid.]
System.Data.Ole Db.OleDbExcepti on..ctor(IError Info errorInfo, Int32
errorCode, Exception inner)
System.Data.Ole Db.OleDbConnect ion.ProcessResu lts(Int32 hResult,
OleDbConnection connection, Object src)
System.Data.Ole Db.OleDbCommand .ExecuteCommand TextErrorHandli ng(Int32 hr)

System.Data.Ole Db.OleDbCommand .ExecuteCommand TextForSingleRe sult(tagDBPARAM S
dbParams, Object& executeResult)
System.Data.Ole Db.OleDbCommand .ExecuteCommand Text(Object& executeResult)
System.Data.Ole Db.OleDbCommand .ExecuteCommand (CommandBehavio r behavior,
Object& executeResult)
System.Data.Ole Db.OleDbCommand .ExecuteReaderI nternal(Command Behavior
behavior, String method)
System.Data.Ole Db.OleDbCommand .ExecuteScalar( )
WebPDB2.Global. Session_Start(O bject sender, EventArgs e) in
C:\Inetpub\wwwr oot\WebPDB2\Glo bal.asax.vb:73
System.Web.Sess ionState.Sessio nStateModule.Ra iseOnStart(Even tArgs e)
System.Web.Sess ionState.Sessio nStateModule.On Start(EventArgs e)
System.Web.Sess ionState.Sessio nStateModule.Co mpleteAcquireSt ate()
System.Web.Sess ionState.Sessio nStateModule.Be ginAcquireState (Object
source, EventArgs e, AsyncCallback cb, Object extraData)

System.Web.Asyn cEventExecution Step.System.Web .HttpApplicatio n+IExecutionSte p
..Execute()
System.Web.Http Application.Exe cuteStep(IExecu tionStep step, Boolean&
completedSynchr onously) +173


"Patrick Steele [MVP]" <pa*****@mvps.o rg> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
In article <40********@new s.hcs.net>, john@nowhere says...
Dim temp As Object = cmd1.ExecuteSca lar

Amazing - this gives the same error.


Very odd... Does the Exception that is thrown contain anything in the
"InnerException " property? There's got to be a stack trace somewhere
showing exactly what is throwing the invalid cast exception.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele

Nov 20 '05 #7
* "John Howard" <john@nowhere > scripsit:
Making the following call to a local MSAccess database works fine:

Sub Session_Start(B yVal 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
.connectionstri ng = "provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=C:\PDB\D evelopment\Data base\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.ExecuteSca lar
However, changing the connectionstrin g to

.ConnectionStri ng = "Provider=M S Remote;" & _
"Remote Server=http://scfmzcp1;" & _
"Remote Provider=Micros oft.Jet.OLEDB.4 .0;" & _
"Data Source=W:\PDB\D evelopment\PDB. mdb;" & _
"Connection Timeout=30"

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


.... I suggest to ask this question in a more appropriate group:

<URL:news://news.microsoft. com/microsoft.publi c.dotnet.framew ork.adonet>

Web interface:

<URL:http://msdn.microsoft. com/newsgroups/?dg=microsoft.p ublic.dotnet.fr amework.adonet>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8
Hi John,

Is the field description of both databases equal

You can of course just try this
Dim strSystemName As Integer = Cint(cmd1.Execu teScalar)

Just a thought,

Cor
Nov 20 '05 #9
Same error again.

Specified cast is not valid.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.InvalidC astException: Specified cast is not
valid.

Source Error:
Line 70: End With
Line 71: ' Execute the SQL
Line 72: Dim strSystemName As Integer =
CInt(cmd1.Execu teScalar)
Line 73: 'Dim dr As OleDbDataReader = cmd1.ExecuteRea der
Line 74: 'Dim temp As Object = cmd1.ExecuteSca lar
Source File: C:\Inetpub\wwwr oot\WebPDB2\Glo bal.asax.vb Line: 72

Stack Trace:
[InvalidCastExce ption: Specified cast is not valid.]
System.Data.Ole Db.OleDbExcepti on..ctor(IError Info errorInfo, Int32
errorCode, Exception inner)
System.Data.Ole Db.OleDbConnect ion.ProcessResu lts(Int32 hResult,
OleDbConnection connection, Object src)

System.Data.Ole Db.OleDbCommand .ExecuteCommand TextErrorHandli ng(Int32
hr)

System.Data.Ole Db.OleDbCommand .ExecuteCommand TextForSingleRe sult(tagDBPARAM S
dbParams, Object& executeResult)
System.Data.Ole Db.OleDbCommand .ExecuteCommand Text(Object&
executeResult)
System.Data.Ole Db.OleDbCommand .ExecuteCommand (CommandBehavio r
behavior, Object& executeResult)

System.Data.Ole Db.OleDbCommand .ExecuteReaderI nternal(Command Behavior
behavior, String method)
System.Data.Ole Db.OleDbCommand .ExecuteScalar( )
WebPDB2.Global. Session_Start(O bject sender, EventArgs e) in
C:\Inetpub\wwwr oot\WebPDB2\Glo bal.asax.vb:72
System.Web.Sess ionState.Sessio nStateModule.Ra iseOnStart(Even tArgs
e)
System.Web.Sess ionState.Sessio nStateModule.On Start(EventArgs e)
System.Web.Sess ionState.Sessio nStateModule.Co mpleteAcquireSt ate()
System.Web.Sess ionState.Sessio nStateModule.Be ginAcquireState (Object
source, EventArgs e, AsyncCallback cb, Object extraData)

System.Web.Asyn cEventExecution Step.System.Web .HttpApplicatio n+IExecutionSte p.Execute()
System.Web.Http Application.Exe cuteStep(IExecu tionStep step,
Boolean& completedSynchr onously) +173


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.432 2.573;
ASP.NET Version:1.1.432 2.573

On Tue, 8 Jun 2004 20:34:58 +0200, "Cor Ligthert"
<no**********@p lanet.nl> wrote:
Hi John,

Is the field description of both databases equal

You can of course just try this
Dim strSystemName As Integer = Cint(cmd1.Execu teScalar)

Just a thought,

Cor


Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
31012
by: Krung Saengpole | last post by:
Hi, I used SQL Server 2000 Personal Edition. I created a stored procedure having input parameters as smallint,tinyint,char,varchar and smalldatetime. When I executed it by Query Analyzer, it's ok. But when I executed it by ASP code that used ADODB.command, it showed error: Invalid character value for cast specification . Though SQL...
3
13874
by: Giulio Santorini | last post by:
Hi, I've got a little problem with my C# WinForms test application. I would like to have a ComboBox showing a a visual value and some hidden values. So I build a class able to store thoose values. This class called ListItem have got two private variable, one is a string containing the visual value, the other one is a UDT variable. It is...
0
1677
by: Alan Z. Scharf | last post by:
Win Server 2003 VS.Net 2003 --------------- 1. I'm having the same problem below on all six of my pages with a datagrid item. 2. These pages all worked fine for months until problem started. 3. Same problem on two different computers running Win 2003.
5
3399
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to...
2
2230
by: adams114 | last post by:
I am having a strange problem with invalid type casts. I am trying to update a MS SQL Database with a stored procedure. When I setup the parameters collection for the command object I get a invalid cast exception error: Compiler Error Message: BC30311: Value of type 'Date' cannot be converted to 'Integer'. The real problem here is that...
3
2267
by: John Howard | last post by:
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 =
1
4856
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm specifiying my code: The Code used in Visual Studio: Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As String, ByVal...
15
2224
by: David | last post by:
Hi, I have built a web application that will be a very high profile application. We had tested it, demonstrated it and shown that it all works. On a dress rehearsal run through, it failed spectacularly. I was so embarrassed and felt like killing the person that made it fail. However, when it goes live, IT MUST NOT FAIL. The system has...
7
3597
by: Chris Thunell | last post by:
I'm trying to loop through an exchange public folder contact list, get some information out of each item, and then put it into a vb.net datatable. I run though the code and all works fine until i get to item 250 i get a "system.invalid cast exception" and "specified cast is not valid". Once i get this error and try to go to the next record.....
0
7410
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7668
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
5984
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3466
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.