Connecting to an Instance of SQL Server
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Connecting to an Instance of SQL Server

  1. #1
    Join Date
    Apr 2009
    Location
    Ohio Summit County
    Posts
    114

    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
    ToppersBBS on the web - http://toppersbbs.dtdns.net
    Forums Section - http://toppersbbs.dtdns.net/smf

  2. #2
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    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.

  3. #3
    Join Date
    Apr 2009
    Location
    Ohio Summit County
    Posts
    114

    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.
    ToppersBBS on the web - http://toppersbbs.dtdns.net
    Forums Section - http://toppersbbs.dtdns.net/smf

  4. #4
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    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.

  5. #5
    Join Date
    Apr 2009
    Location
    Ohio Summit County
    Posts
    114

    Re: Connecting to an Instance of SQL Server

    Quote Originally Posted by eclipsed4utoo View Post
    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.
    ToppersBBS on the web - http://toppersbbs.dtdns.net
    Forums Section - http://toppersbbs.dtdns.net/smf

  6. #6
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: Connecting to an Instance of SQL Server

    Quote Originally Posted by bigjoe11a View Post

    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?

  7. #7
    Join Date
    Apr 2009
    Location
    Ohio Summit County
    Posts
    114

    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.
    ToppersBBS on the web - http://toppersbbs.dtdns.net
    Forums Section - http://toppersbbs.dtdns.net/smf

  8. #8
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: Connecting to an Instance of SQL Server

    Quote Originally Posted by bigjoe11a View Post
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center