473,382 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Connecting to a SQL Server 2005 Database

Greetings,

I am using Visual C#.NET 2005 (Express Edition) and want to connect to a SQL
Server 2005 (Express Edition) database. When I attempt to compile the code
below, however, I receive the error message:

"Use of unassigned local variable 'con'"

System.Data.SqlClient.SqlConnection con;
con.ConnectionString = "Data Source=HOME-PC\\SQLEXPRESS;Initial
Catalog=Contacts;User ID=sa";
con.Open();

Any ideas as to what I am doing wrong?

Thanks in advance!
Jun 27 '08 #1
2 1044
Sherwood wrote:
I am using Visual C#.NET 2005 (Express Edition) and want to connect to a SQL
Server 2005 (Express Edition) database. When I attempt to compile the code
below, however, I receive the error message:

"Use of unassigned local variable 'con'"

System.Data.SqlClient.SqlConnection con;
con.ConnectionString = "Data Source=HOME-PC\\SQLEXPRESS;Initial
Catalog=Contacts;User ID=sa";
con.Open();

Any ideas as to what I am doing wrong?
You are missing something like:

con = new SqlConnection();

Arne

Jun 27 '08 #2
Try this

System.Data.SqlClient.SqlConnection con;
con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString = "Data Source=HOME-PC\\SQLEXPRESS;Initial
Catalog=Contacts;User ID=sa";
con.Open();
--
Regards,
Mudassar Hassan
Software Engineer
http://mudassarhassan.spaces.live.com/
"Sherwood" wrote:
Greetings,

I am using Visual C#.NET 2005 (Express Edition) and want to connect to a SQL
Server 2005 (Express Edition) database. When I attempt to compile the code
below, however, I receive the error message:

"Use of unassigned local variable 'con'"

System.Data.SqlClient.SqlConnection con;
con.ConnectionString = "Data Source=HOME-PC\\SQLEXPRESS;Initial
Catalog=Contacts;User ID=sa";
con.Open();

Any ideas as to what I am doing wrong?

Thanks in advance!
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed...
3
by: Ann Marinas | last post by:
Hi there, I am currently developing an ASP.NET program that connects to a SQL Server 2000 database. I also have SQL Server 2005 Express installed on the same local machine. Prior to...
0
by: acwomble | last post by:
I am working with a database on another system via a ssh tunnel using plink. We have setup an alias the local system for the remote database. I am able to connect and work from within Visual...
2
by: hfk0 | last post by:
Hello, I'm a newbie here and was wondering anyone could help me with this. I have a simple ASP.NET 2 web application running perfectly fine with IIS and SQLServerExpress installed locally on...
2
by: Patrick F | last post by:
Hi, i have SQL Server 2005 and a database set that is called, myCompany the problem is that i cant connect from my page to it, here is from the web.config: ( i have got this connectionstring from...
1
by: =?Utf-8?B?TmVpbCBQYWRkb2Nr?= | last post by:
Using asp.net in Visual Studio 2005, we are getting an error message when trying to connect to an existing SQL 2000 database.. This has only hapenned since we installed the SQL 2005 client tools....
7
by: TerpZebra | last post by:
I am having difficulty connecting to SQL Server 2000 on one of our servers via a VB6 program on Vista. I can connect fine to a different server, but it gives me the following error with the server...
2
by: samadams_2006 | last post by:
Hello, I have a problem that I'm hoping someone will be able to help me resolve. 1) I have a C# Web Site in which I connect to the database: "Install Microsoft SQL Server 2005 Express...
3
by: Me LK | last post by:
I did a search but could not find an aswer that worked so here it goes. I just did an upgrade from 2003 to vs 2005 express. I am using a remote sql server 2000. I specifically upgrade to make...
1
by: Lou Civitella | last post by:
I created a test web site with VS2008 using Framework 2.0. Created a database in SQL Server 2005 and am able to connect to it without any problems. I then setup the database to be accessed using a...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.