Showing posts with label unhandled. Show all posts
Showing posts with label unhandled. Show all posts

Wednesday, March 21, 2012

help -Object reference not set to an instance of an object.

i m new for asp.net

when i run app. i got this error,

-----
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:

Line 49:
Line 50: adpt.Fill(ds, "SMS_student_class_master")
Line 51: txt.Text = ds.Tables.Item("roll_no").ToString
Line 52: con.Close()
Line 53: End Sub

Source File: c:\inetpub\wwwroot\aspnet\sms\assignment_d.aspx.vb Line: 51
------

my source code given below,

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsNothing(Request.QueryString("id")) Then
sid = Request.QueryString("id")
End If
Dim con As New SqlConnection
Dim constr As String
Dim cmd As New SqlCommand
Dim ds As New DataSet
Dim adpt As New SqlDataAdapter

constr = "data source=Baroda;user id=sa;password=;" & _
"initial catalog=SMS;persist security info=False;workstation id=Baroda;Packet size=4096"
con.ConnectionString = constr
con.Open()

cmd.CommandText = "SELECT * FROM SMS_student_class_master WHERE " & _
"stud_id='" + sid + "'"
cmd.Connection = con
adpt.SelectCommand = cmd

adpt.Fill(ds, "SMS_student_class_master")
txt.Text = ds.Tables.Item("roll_no").ToString
con.Close()
End Sub
---

what should i do?
anyone have any idea?
plz give solution.
its urgent.

thanks in advance.cmd.Connection = con
adpt = new SqlDataAdapter(cmd)
adpt.Fill(...)

Monday, March 19, 2012

Help Needed!! Error connecting to SQL 2005 EE via VB 2005 EE

System.Data.SqlClient.SqlException was unhandled
Class=20
ErrorCode=-2146232060
LineNumber=0
Message="An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
Number=2
Server=""
Source=".Net SqlClient Data Provider"
State=0

Hi guys, I have just set up a database in SQL 2005 Express Edition. However, I have a problem accessing it with the application program created in VB 2005 EE. Before using SQL 2005, the application worked perfectly in SQL 2000.
Here is my connection string used in SQL 2000:

Dim sqlConn As New SqlConnection("Data Source=(local); Database='Inventory List'; Integrated Security=yes")

Is this valid in SQL 2005 Express Edition? Or should I change the connection string instead? Thank you very much.

The normal connection string for express would be;

Dim sqlConn As New SqlConnection("Data Source=(local)\sqlexpress; Database='Inventory List'; Integrated Security=yes")

|||Did you enable remote connections for the SQL Express instance ? See the Screencast on my site for more information.

Jens K. Suessmeyer.

http://www.sqlserver2005.de