hallo,
if I run this login in my localserver it works. If I run it in the remote server I get an error:
object reference not set to an instance of the object.
The highlighted line is where I close the objreader after the try. Do you know what it could be? Thanks
sub Login(obj as object, e as eventargs)
dim intId as integer = 0
dim Conn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\inetpub\wwwroot\new1\blog.mdb")
dim objCmd as OleDbCommand = new OleDbCommand("spValidateUser", Conn)
objCmd.CommandType = CommandType.StoredProcedure
dim objReader as OleDbDataReader
'set parameters for stored procedure
dim objParam as OleDbParameter
objParam = objCmd.Parameters.Add("@dotnet.itags.org.UserName", OleDbType.BSTR)
objParam.Direction = ParameterDirection.Input
objParam.Value = tbUserName.Text
objParam = objCmd.Parameters.Add("@dotnet.itags.org.Password", OleDbType.BSTR)
objParam.Direction = ParameterDirection.Input
objParam.Value = tbPassword.Text
try
objCmd.Connection.Open()
objReader = objCmd.ExecuteReader
do while objReader.Read
intId = objReader.GetInt32(0).ToString
loop
catch ex as OleDbException
lblMessage.Text = ex.Message
finally
objReader.Close
objCmd.Connection.Close()
end try
if intID <> 0 then
FormsAuthentication.SetAuthCookie(intID, false)
Response.redirect("blog_edit.aspx")
else
lblMessage.Text = "<span class=""t_err"">Sorry, invalid username or password!</span>"
end if
end sub
Just a guess but do you have write permissions on the server for the folder where your access database (.mdb) resides?
Grz, Kris.
I think I have... I mean, I can access the database even before the login (every user can) and add data. This means that I have permissions (or not?).
It appears that an exception is being thrown in either the first or second line of code in the Try block before objReader is instantiated. Then, when you attempt to close objReader in the Finally block, objReader is Nothing, throwing another exception.
For this reason, I usually code my Finally blocks as follows:
If Not objReader Is Nothing Then objReader.Close()
If Not Conn Is Nothing Then
If Conn= ConnectionState.Open Then Conn.Close()
Conn.Dispose()
End If
Once you make these changes and prevent the second exception from being thrown, you should be able to see in lblMessage the cause of the first exception. I suspect that it is being thrown when opening the connection as the connection string looks more like that for your local server rather than the remote server.
imagemaker wrote:
I suspect that it is being thrown when opening the connection as the connection string looks more like that for your local server rather than the remote server.
Imagemaker is correct about that: C:\inetpub\wwwroot\new1\blog.mdb looks like your own drive. You can useServer.Mappath for this.
Grz, Kris.
0 comments:
Post a Comment