-
June 1st, 2009, 08:47 AM
#1
Connecting to an Instance of SQL Server
How can I connect to a SQL Server in a console application in VC# express.
I'm trying to access a SQL Server to connect to databases in SQL Server to list, edit and delete records from a table.
Does any one know how to do this.
Joe
-
June 1st, 2009, 12:01 PM
#2
Re: Connecting to an Instance of SQL Server
which type? SQL Server 2000/2005/2008 or SQL Compact?
oh, and you should probably try a search. This is probably one of the most asked questions.
Look into using ADO.Net. I always recommend using the SqlConnection, SqlCommand, and SqlDataReader classes, but there are other ways of connecting.
-
June 1st, 2009, 12:20 PM
#3
Re: Connecting to an Instance of SQL Server
I'm using SQL server Express 2008. In a VC# Console Application.
And Yes I used those commands before. The problem I'm having is when I use a SQL Server database file. The program gets all messaed up when it tries to read the database file. When your running the program it connects to the database in the debug folder. and when your in the IDE it looks and access the sql server database file in the root folder. I was told to just access SQL Server and use that instead of what I was trying to do before.
-
June 1st, 2009, 12:25 PM
#4
Re: Connecting to an Instance of SQL Server
I always suggest connecting to the instance and not the actual file.
Did you add this database using the "Add New Item..." window? If so, the database file is a SQL Compact database.
If you did not add the database this way and you did install SQL Express, then you DO NOT attach the database file to the project. You connect to the service(instance), not to the file.
-
June 1st, 2009, 12:56 PM
#5
Re: Connecting to an Instance of SQL Server
Originally Posted by eclipsed4utoo
I always suggest connecting to the instance and not the actual file.
Did you add this database using the "Add New Item..." window? If so, the database file is a SQL Compact database.
If you did not add the database this way and you did install SQL Express, then you DO NOT attach the database file to the project. You connect to the service(instance), not to the file.
To answer your questions Yes. And it didn't matter how I set it up. I still had problems with 2 database files. The one in the root folder and the one in the debug folder. I added a new record into the database when I was running in debug mode. So the new record got added to the database file in the debug folder.
I just add this file into sql server 2008 express with the Management Studio and all I want to know is how to add some thing in my program to access sql server and not the database file. That way it will point only one file. And this should fix my problem.
I just didn't see any option to connect to it.
There's only 3 options to use.
1) Microsoft Access database
2) Microsoft SQL Server Compact 3.5
3) Microsoft SQL Server database File.
There's no option to connect to the SQL Server.
-
June 1st, 2009, 01:27 PM
#6
Re: Connecting to an Instance of SQL Server
Originally Posted by bigjoe11a
There's only 3 options to use.
1) Microsoft Access database
2) Microsoft SQL Server Compact 3.5
3) Microsoft SQL Server database File.
There's no option to connect to the SQL Server.
where do you see these options at?
-
June 1st, 2009, 01:54 PM
#7
Re: Connecting to an Instance of SQL Server
When I setup a database. You should see this every time you want to access a sql server database in your applications. How could you not know what this is.
-
June 2nd, 2009, 09:27 AM
#8
Re: Connecting to an Instance of SQL Server
Originally Posted by bigjoe11a
When I setup a database. You should see this every time you want to access a sql server database in your applications. How could you not know what this is.
I have added a "Local Database" to numerous projects and connected remotely to numerous Service-Based databases, and I have never seen those options.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|