473,847 Members | 1,863 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 1933
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
31035
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 Server debugger, it showed: Invalid character value for cast
3
13895
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 a struct called
0
1688
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
3447
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 provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
2
2243
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 the type in the database and the stored prcedure aren't integers at all rather they are datetime...
3
2296
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
4921
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 iDate As Date) As String 'Dim Ret As Integer
15
2265
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 a backoffice system that takes an excel spreadsheet from the
7
3633
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.. every record after gets the same error... It's like the com connection to outlook has been lost....
0
9879
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10978
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10643
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10705
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9477
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7879
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4521
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
2
4113
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3158
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.