WebServices Not Liking Something

philprice

Well-known member
Joined
Mar 21, 2003
Messages
116
Location
Hull, UK
Right,

Just started out with webservies Im getting:

Code:
An unhandled exception of type System.Web.Services.Protocols.SoapException occurred in system.web.services.dll

Additional information: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at NewsThingSite.NewsThing.CloseConnectionToMDB() in C:\Inetpub\wwwroot\NewsThingSite\NewsThing.asmx.vb:line 129
   at NewsThingSite.NewsThing.createNewUser(String strName, String strEmail) in C:\Inetpub\wwwroot\NewsThingSite\NewsThing.asmx.vb:line 106
   --- End of inner exception stack trace ---

From

Code:
    <WebMethod(Description:="Create a new user", EnableSession:=True)> _
    Public Function createNewUser() As String

        Dim strNewGuid As String
        Dim strSQL As String

        strNewGuid = System.Guid.NewGuid().ToString

        OpenConnectionToMDB()
        strSQL = "INSERT INTO user(GUID) VALUES(" + strNewGuid + ")"

        Try
            oCmd.CommandText = strSQL
            oCmd.ExecuteNonQuery()
        Catch strE As Exception
            Debug.WriteLine(strE)
        End Try
        CloseConnectionToMDB()

        Return strNewGuid

    End Function

And i dont know what it means, what am i doing wrong?
 
What does CloseConnectionToMDB look like? It looks like thats
where the error is happening.
 
I was using the wrong connection string, i need the path to the MDB file but i reliased, the current directory is not the one where the current files are. I need some way of getting it in ASP.
 
I think using Server.MapPath("myMDB.mdb") will get the proper
path to the file in ASP, assuming its in the same directory as the
ASP file. If its not, then Server.MapPath("myDir\myMDB.mdb")
then.
 
Haha, cheers.

Now another problem, im getting an error saying its "exclusivly opened by another program" or something, but its not - grr this is so frustrating. Im using OleDB with access. sigh.
 
Are you sure youre not opening the database twice in your
program (i.e. calling OpenConnectionToMDB and forgetting to close
it after youre done)?

Also, did Access crash while the database was open, or did you close
it unusually? If it did, theres a chance that the database is locked.
Look to see if theres a .ldb file in the directory with the database.
 
Okay ive fixed the open / close thing, now its telling there are errors with my sql, and its getting really annoying.

Code:
System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
   at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr)

from INSERT INTO user (userGUID, name, email) VALUES (ce7047f9-c3c9-414e-ac69-d48717a9bbcc, , );

The thing is the above statement works FINE in Access, i dont get it..
 
Thanks derek, working now, but im still frustrated, im getting a internal 500 error, from a method ive written getCatagoryByID(ID As int32), if i enter a catagory that is not there, i get a nice error, but if i do, all i get is an internal error, now the code..

Code:
strSQL = "SELECT ID, catName FROM catagory WHERE ID=" + intID.ToString
        OpenConnectionToMDB()
        myCmd.CommandText = strSQL
        myReader = myCmd.ExecuteReader(CommandBehavior.SingleRow)

        myReader.Read()
        myCat.catagoryID = CInt(myReader.GetString(0))
        myCat.catagoryName = myReader.GetString(1)

        CloseConnectionToMDB()

        Return myCat

PS Sorry about posting all this code... Ive been at this for ages and im finding it really really frustrating.
 
You should probably check to see if your DataReaders HasRows
property is set to True before you try and get the data out of it. If
your query didnt return anything, then you cant get data out of the
reader, obviously. Not sure if thats your problem, though.
 
That helps if there is no data, i.e. a incorrect id which is cool. But it still give a 500 when there is data, this is REALLY weird, i cant actually track down the error which is really annoying.
 
You might want to change those ordinals from hardcoded values into calls to GetOrdinal. This will save you time, increase readability and lessen chances of incorrect ordinal references in the future. Just a suggestion, no biggie.
 
Back
Top