Click here to Skip to main content
14,699,491 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 23: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

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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900