John:
This is the response:
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.InvalidCastException: Specified cast is not
valid.
Source Error:
Line 75: Dim strSystemName As Integer
Line 76: 'Dim strSystemName As Integer = cmd1.ExecuteScalar
Line 77: Dim o As Object = cmd1.ExecuteScalar
Line 78: Response.Write(o.GetType().ToString())
Line 79: '
-----------------------------------------------------------
Source File: C:\Inetpub\wwwroot\WebPDB2\Global.asax.vb Line: 77
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
System.Data.OleDb.OleDbException..ctor(IErrorInfo errorInfo, Int32
errorCode, Exception inner)
System.Data.OleDb.OleDbConnection.ProcessResults(I nt32 hResult,
OleDbConnection connection, Object src)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32
hr)
System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS
dbParams, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object&
executeResult)
System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior
behavior, Object& executeResult)
System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior
behavior, String method)
System.Data.OleDb.OleDbCommand.ExecuteScalar()
WebPDB2.Global.Session_Start(Object sender, EventArgs e) in
C:\Inetpub\wwwroot\WebPDB2\Global.asax.vb:77
System.Web.SessionState.SessionStateModule.RaiseOn Start(EventArgs
e)
System.Web.SessionState.SessionStateModule.OnStart (EventArgs e)
System.Web.SessionState.SessionStateModule.Complet eAcquireState()
System.Web.SessionState.SessionStateModule.BeginAc quireState(Object
source, EventArgs e, AsyncCallback cb, Object extraData)
System.Web.AsyncEventExecutionStep.System.Web.Http Application+IExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step,
Boolean& completedSynchronously) +173
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573;
ASP.NET Version:1.1.4322.573
On Tue, 8 Jun 2004 17:08:09 -0400, "John Saunders"
<jo**************@notcoldmail.com> wrote:
"John Howard" <me@somewhere> wrote in message
news:oq********************************@4ax.com.. . Making the following call to a local MSAccess database works fine:
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
...
Dim strSystemName As Integer = cmd1.ExecuteScalar
If you get a "specified cast is invalid" exception, then you should ask
yourself which cast it's referring to.
Now, there's no cast visible on that line because VB.NET is allowing you to
get away without one (try turning Options Strict On). There's an implicit
cast to Integer:
Dim strSystemName as Integer = CType(cmd1.ExecuteScalar, Integer)
So, if the "specified cast is invalid", then it suggests that the
ExecuteScalar call is returning something which cannot be cast to an Integer
(in other words, it's not returning an integer). You might try the
following:
Dim o As Object = cmd1.ExecuteScalar
Response.Write (o.GetType().ToString())
Another clue is the fact that you named the variable "strSystemName", but
you say it is of type "Integer". Maybe the ExecuteScalar is returning a
string?