When I try to open a connection to the database I hit an error
"Object reference not set to an instance of an object."
I have make a simple test connection function same error coming out when open connection as the line in 9 "connect.Open() ;". Here my function: - private void butConnect_Click(object sender, System.EventArgs e)
-
{
-
SqlConnection connect = null;
-
try
-
{
-
connect = new SqlConnection();
-
connect.ConnectionString = "Data Source=(local);Initial Catalog=DB;User ID=sa;Password=password";
-
-
connect.Open();
-
}
-
catch (Exception ex)
-
{
-
MessageBox.Show(ex.Message);
-
}
-
}
My program is in .NET 1.1. Dunno why the error occur, it work fine previously. Thank you for someone help.
8 1411
Hi
I have never used the (local) context for Datasource
Try using the follwing and directing it to the instance name - connect.ConnectionString = "Data Source=.\<SQL server instance>;Initial Catalog=DB;User ID=sa;Password=password";
The default instance name for sql express is SQLEXPRESS
so make the value of Data Source=.\SQLEXP RESS
change accordingly for your servers instance name
cheers
I am using MSSQL Server 2000. I have try so, even how I use in the Data Source neither server name nor IP still come out the same error.
1. Are you able to open the database in the management studio?
2. create a new connection string from visual studio and copy that connection string into your current one. (easy way out)
Enterprise Manager no problem the database can be access or modify. Query Analyzer run script also ok.
My connection string is generate by Visual Studio and the string I had use for many program.
Could you please check which line gives that exception, and which object is staying null !
cheers
The line that cause the problem is number 9 "connect.Open() ;" the line in bold.
When run thought the "connect.Open() ;" it will direct to the Exception and return "Object reference ......".
I wonders why just a simple open connection function cause me waste lot of time. SIGH.
So you mean to say that the line which sets the value for connect.Connect ionString works perfectly, but when it comes to open, the connect suddenly goes null?
Hmmm.... Hows that possible?
Hope someone can put some light on this one...
cheers
Really that happen just when open();
Firewall had been disable.
When test with other computer no problem.
Test open connection in Visual Studio 2005 is ok.
I wonders is it my Visual Studio 2003 problem. If yes what is the problem?
SIGH SIGH....
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bob |
last post by:
I have an ASP.NET web application that has been running without any problems for a while. I recently transferred the site to shared hosting and had multiple users start to use the site. The problem I'm experiencing is that when many users are hitting the site at once, occasionaly I will see errors. The 3 most common ones are: "The SqlCommand is currently busy Open, Fetching. ", "Internal Connection Fatal Error", "object reference not set to...
|
by: Joe Bloggs |
last post by:
I am trying display the contents of a table in a web page, select
certain rows from that table and then display the fields that I have
selected (now table columns) as text in a Label object. Amazingly I have
managed to display the table - no problem, I can select rows - no
problem, BUT I can't work out how to display more than one of the fields
(now columns in the table in the web page). I can display one field OK,
but not more than one...
|
by: Skip Key |
last post by:
While writing a windows service, I've run into a fairly strange problem. I
have a worker proc that gets fired every n seconds using
System.Threading.Timer. This works fine, unless I open an SqlConnection on
it. Just as soon as I do so, the proc fires that time, and never again.
The connection is valid, I can do SQL commands on in with no problems, but
my timer goes away.
Here's a fairly simple console sample that shows the problem....
|
by: VB Programmer |
last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally.
Example: In order to close/dispose a db connection you have to dim the
connection outside of the Try Catch Finally block. But, I prefer to dim them
"on the fly" only if needed (save as much resources as possible). A little
further... I may wish to create a sqlcommand and datareader object ONLY if
certain conditions are met. But, if I want to clean these up in the...
|
by: mhnazly |
last post by:
i'm trying to read data from SQL Server database using
data reader and assigned it to a label in my asp.net web
application. but when the button is clicked, nothing
appears. please help, thanks.
Private Sub btnTesting_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnTesting.Click
Dim cn As New SqlClient.SqlConnection
Dim cm As New SqlClient.SqlCommand
| |
by: Nithin |
last post by:
My code as an txt attachment.
I have 2 drop down list boxes that on selection populate text boxes
from my database table. I am able to display the correct values in
these text boxes.
I have 2 questions:
1) I would like the user update these text fields that get populated
with data from the database. For some reason I get the error when I
change the textbox value.
|
by: Bass Pro |
last post by:
Hi,
I am creating textbox, radiobuttonlist and checkboxlist dynamically
depending on data from a table. It is a questionnaire.
I add the control on a Panel control during the 1st load_page event.
Each question is displayed and answered, then result written to a SQL table.
Then the next question is read from a table and displayed using the
load_page event again.
The questions display and function perfectly. The user anwers the question...
|
by: Usman Jamil |
last post by:
Hi
I've a class that creates a connection to a database, gets and loop on a
dataset given a query and then close the connection. When I use netstat
viewer to see if there is any connection open left, I always see that there
are 2 connections open and in "ESTABLISHED" state. Here is the piece of code
that I'm using, please tell where I'm doing it wrong. Since this class is
being used at many placed in my actual web based application that...
|
by: sweatha |
last post by:
Hi friends
This is sweatha, fresher MCA 2007 batch. Right now I am working in asp.net platform.
My dillema is that I have created a registration form with the fields as username & password. And if once the user register the username and password, it will be stored in the database(SQL Server 2000) by showing "Records Inserted".
Then I have created the login form just like the fields as username and password.And if the user enters the values...
|
by: sirdavethebrave |
last post by:
Hi guys -
I have written a form, and a stored procedure to update the said form.
It really is as simple as that. A user can go into the form, update some fields and hit the update button to update the information which is stored in a SQL database.
In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |