Hello folks,it is my first time here in the Forum,let me explain my situation:
I have a little problem right here in my asp.net (vb.net) application.
I've made small application,with a class to make an access to the database.
I've also a master page to make a default layout.
and finally I've made some web forms.
When I work in my localhost using the visual studio my application works fine,
but when I published my application to the server I got an error.
the error is:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Usuários_Web.WebForm2.cmd_Login_Click(Object sender, EventArgs e) in C:\Users\rborges\Desktop\New_Mes\Usuários Web\Login.aspx.vb:34
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
I've seen that the error happens when I try to execute some queries in my class which makes the connection with the database.
For example,the vb:34 in my Login.aspx has the command line " If rdA.sqlReader.Read() Then "
All the web forms which uses my class to make a connection with the database will show the error.
For example,I have a web form which has no database connection,it has just a "welcome" message and it works fine.
I really don't know what can I do to solve the error.
Folks,if you have some ideas to solve it please send me these ideas to solve this strange error.
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports System.Security
Imports System.Security.Principal.WindowsIdentity
Partial Public Class WebForm2
Inherits System.Web.UI.Page
Public rdA As New Class_Reader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'------------------------------------
Dim Usuario As String
Usuario = (Mid(GetCurrent.Name, 6))
'rdA.ExecuteQuery("Select * from GB_TB_Usuario_Liberado where Usuario_Liberado = '" & Usuario & "'",SPI_BD_GROB_PERFORMANCE")
'If rdA.sqlReader.Read() Then
'Me.Response.Redirect("boas_Vindas.aspx?titulo=1&menu=1&Login=L" & Usuario)
'End If
'rdA.CloseConnection()
'------------------------------------
End Sub
Protected Sub cmd_Limpar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmd_Limpar.Click
'------------------------------------
txt_login.Text = ""
txt_senha.Text = ""
Response.Redirect("Login.aspx")
'------------------------------------
End Sub
Protected Sub cmd_Login_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmd_Login.Click
'------------------------------------
Dim QueryComando As String
QueryComando = "Select * from SPI_TB_USUARIO WHERE LOGIN_USU = '" & txt_login.Text.Trim & "' and SENHA_USU = '" & txt_senha.Text.Trim & "' "
rdA.ExecuteQuery(QueryComando, "SPI_BD_GROB_PERFORMANCE")
If rdA.sqlReader.Read() Then
Me.Response.Redirect("boas_Vindas.aspx?titulo=1&menu=1&Login=" & txt_login.Text)
Else
Response.Redirect("Login.aspx")
End If
'------------------------------------
End Sub
Public Class Class_Reader
'classe de conexão com o DataReader
Public connetionString As String
Public sqlCnn As SqlConnection
Public sqlCmd As SqlCommand
Public sql As String
Public sqlReader As SqlDataReader
Public Sub ExecuteQuery(ByVal strQuery As String, ByVal BancoDeDados As String)
' ***************************************************************************************
connetionString = "Data Source=TAU;Initial Catalog='" & BancoDeDados & "';Integrated Security=SSPI;"
sqlCnn = New SqlConnection(connetionString)
Try
sqlCnn.Open()
sqlCmd = New SqlCommand(strQuery, sqlCnn)
sqlReader = sqlCmd.ExecuteReader()
Catch ex As Exception
' write an exception here
End Try
' ***************************************************************************************
End Sub
Public Sub CloseConnection()
' ***************************************************************************************
Try
sqlReader.Close()
sqlCmd.Dispose()
sqlCnn.Close()
Catch ex As Exception
' write an exception here
End Try
' ***************************************************************************************
End Sub
End Class
I'm publishing it on a Server which already has another asp.net application but I did not develop that application.
I'm trying to publish a new application and I'm little bit confuse...
I've posted the code of my class which makes the connection with the database,there's a server and its name is TAU,this is the server where I've published my application.
You have not shared your connection string (which is OK since it is sensitive)
so yes I think the problem is with connection string that you have either in the class: Class_Reader
Or in the web.config file
So when you do it locally, you are connecting with a database that is available on your local machine only
to deploy it to server, you must change your connection string, to point to the database that is available on server
Rafael Gazza...
Member
1 Points
5 Posts
Object reference not set to an instance of an object after publish/deploy my application
Dec 13, 2012 10:27 AM|LINK
Hello folks,it is my first time here in the Forum,let me explain my situation:
I have a little problem right here in my asp.net (vb.net) application.
I've made small application,with a class to make an access to the database.
I've also a master page to make a default layout.
and finally I've made some web forms.
When I work in my localhost using the visual studio my application works fine,
but when I published my application to the server I got an error.
the error is:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Usuários_Web.WebForm2.cmd_Login_Click(Object sender, EventArgs e) in C:\Users\rborges\Desktop\New_Mes\Usuários Web\Login.aspx.vb:34
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
--------------------------------------------------------------------------------
I've seen that the error happens when I try to execute some queries in my class which makes the connection with the database.
For example,the vb:34 in my Login.aspx has the command line " If rdA.sqlReader.Read() Then "
All the web forms which uses my class to make a connection with the database will show the error.
For example,I have a web form which has no database connection,it has just a "welcome" message and it works fine.
I really don't know what can I do to solve the error.
Folks,if you have some ideas to solve it please send me these ideas to solve this strange error.
Thanks folks!
usman400
Contributor
3503 Points
721 Posts
Re: Object reference not set to an instance of an object after publish/deploy my application
Dec 13, 2012 10:31 AM|LINK
Where are you publishing it?
if you are publishing on local host and trying to access the web site locally, then there should be no error
Otherwise you must change the connection string to point to proper attribute values inside it
oned_gk
All-Star
31651 Points
6468 Posts
Re: Object reference not set to an instance of an object after publish/deploy my application
Dec 13, 2012 10:33 AM|LINK
Rafael Gazza...
Member
1 Points
5 Posts
Re: Object reference not set to an instance of an object after publish/deploy my application
Dec 13, 2012 10:39 AM|LINK
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports System.Security
Imports System.Security.Principal.WindowsIdentity
Partial Public Class WebForm2
Inherits System.Web.UI.Page
Public rdA As New Class_Reader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'------------------------------------
Dim Usuario As String
Usuario = (Mid(GetCurrent.Name, 6))
'rdA.ExecuteQuery("Select * from GB_TB_Usuario_Liberado where Usuario_Liberado = '" & Usuario & "'",SPI_BD_GROB_PERFORMANCE")
'If rdA.sqlReader.Read() Then
'Me.Response.Redirect("boas_Vindas.aspx?titulo=1&menu=1&Login=L" & Usuario)
'End If
'rdA.CloseConnection()
'------------------------------------
End Sub
Protected Sub cmd_Limpar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmd_Limpar.Click
'------------------------------------
txt_login.Text = ""
txt_senha.Text = ""
Response.Redirect("Login.aspx")
'------------------------------------
End Sub
Protected Sub cmd_Login_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmd_Login.Click
'------------------------------------
Dim QueryComando As String
QueryComando = "Select * from SPI_TB_USUARIO WHERE LOGIN_USU = '" & txt_login.Text.Trim & "' and SENHA_USU = '" & txt_senha.Text.Trim & "' "
rdA.ExecuteQuery(QueryComando, "SPI_BD_GROB_PERFORMANCE")
If rdA.sqlReader.Read() Then
Me.Response.Redirect("boas_Vindas.aspx?titulo=1&menu=1&Login=" & txt_login.Text)
Else
Response.Redirect("Login.aspx")
End If
'------------------------------------
End Sub
End Class
Rafael Gazza...
Member
1 Points
5 Posts
Re: Object reference not set to an instance of an object after publish/deploy my application
Dec 13, 2012 10:45 AM|LINK
Imports System.Data.SqlClient
Public Class Class_Reader
'classe de conexão com o DataReader
Public connetionString As String
Public sqlCnn As SqlConnection
Public sqlCmd As SqlCommand
Public sql As String
Public sqlReader As SqlDataReader
Public Sub ExecuteQuery(ByVal strQuery As String, ByVal BancoDeDados As String)
' ***************************************************************************************
connetionString = "Data Source=TAU;Initial Catalog='" & BancoDeDados & "';Integrated Security=SSPI;"
sqlCnn = New SqlConnection(connetionString)
Try
sqlCnn.Open()
sqlCmd = New SqlCommand(strQuery, sqlCnn)
sqlReader = sqlCmd.ExecuteReader()
Catch ex As Exception
' write an exception here
End Try
' ***************************************************************************************
End Sub
Public Sub CloseConnection()
' ***************************************************************************************
Try
sqlReader.Close()
sqlCmd.Dispose()
sqlCnn.Close()
Catch ex As Exception
' write an exception here
End Try
' ***************************************************************************************
End Sub
End Class
Rafael Gazza...
Member
1 Points
5 Posts
Re: Object reference not set to an instance of an object after publish/deploy my application
Dec 13, 2012 10:48 AM|LINK
I'm publishing it on a Server which already has another asp.net application but I did not develop that application.
I'm trying to publish a new application and I'm little bit confuse...
I've posted the code of my class which makes the connection with the database,there's a server and its name is TAU,this is the server where I've published my application.
usman400
Contributor
3503 Points
721 Posts
Re: Object reference not set to an instance of an object after publish/deploy my application
Dec 13, 2012 10:53 AM|LINK
You have not shared your connection string (which is OK since it is sensitive)
so yes I think the problem is with connection string that you have either in the class: Class_Reader
Or in the web.config file
So when you do it locally, you are connecting with a database that is available on your local machine only
to deploy it to server, you must change your connection string, to point to the database that is available on server
it would probably look something like:
Rafael Gazza...
Member
1 Points
5 Posts
Re: Object reference not set to an instance of an object after publish/deploy my application
Dec 13, 2012 11:22 AM|LINK
you got!
Thanks a lot,I've forgotten to create a user to access it,you helped me a lot!
now I can continue with my developing
Thanks again "from Brazil"
usman400
Contributor
3503 Points
721 Posts
Re: Object reference not set to an instance of an object after publish/deploy my application
Dec 14, 2012 03:51 AM|LINK
nice to know ur problem resolved