Click here to Skip to main content
14,665,095 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi all,

I am using 2003 and Sql 2000 server when I am trying to connect to sql server it generates error.
it says "An unhandled exception of type 'System.NullReferenceException' occurred in"

Here is the code. Please help me.
Private Sub ConnectToSQL()
       Dim con As New SqlConnection
       Dim cmd As New SqlCommand
       con.ConnectionString = "Data Source=(local);Initial Catalog=AACA_Library_db;Persist Security Info=True;User ID=lib;Password=lib"
   End Sub

Thank you in advance
Updated 27-May-11 22:49pm
Sandeep Mewara 28-May-11 4:50am
Are you sure, above code snippet has the line that throws the error? I doubt it.

Share the complete stacktrace. There must be a line number too - which line it says?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Have a check of your connection string. here is a good resource to check the string construction Connection Strings[^]

I would also verify your datasource, catalog, username and password

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100