Problem w/C# and SQL connect

120 pts.
Tags:
Access SQL
C
Am running XP, Visual C# 2010 Express and SQL Server Express. Cant connect with Northwind DB (Visual C# 2010 "Step by Step" John Sharp book. Chptr 26.
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

As an addendum to my above-question… When trying to connect to username\sqlexpress, get following error msg.”Cannot connect to name\sqlexpress. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that the SQLServer is configured to allow remote connections. (provider: SQL Network Interfacse, error:26…”

Discuss This Question: 14  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • carlosdl
    To improve your changes of getting a useful response, I would recommend posting the code you are using to connect, and the exact and complete error messages you are getting.
    85,055 pointsBadges:
    report
  • mtboru
    Perhaps the needed database is detached???
    120 pointsBadges:
    report
  • carlosdl
    You don't connect to username\sqlexpress.

    Why don't you want to post your code?
    85,055 pointsBadges:
    report
  • mtboru
    My effort lies with doing the examples in the reference book I cite. There are several pieces of C# code I enter per their instructions, however the issue lies when I try & connect with the database included with their Step By Step cd & click New Connection as instructed in a previous page, I had earlier typed 'sqlcmd -S.\SQLExpress -E -idetach.sql' in order to detach the "Northwind" database. 
    120 pointsBadges:
    report
  • carlosdl
    So, if I understand correctly, the problem is that you detached the database.

    This should help you attach it:

    Attach a Database
    85,055 pointsBadges:
    report
  • mtboru
    Thanks very much. I'll try this following these instructions for my SQL 2008 version & keep you posted. Per the C# book, their steps for getting access to their database includes using the Security page within the database's Properties dialog. I do NOT get to the Security
    page...
    120 pointsBadges:
    report
  • mtboru

    When attempting to connect to the book's example database (Northwind.mdf) per step#3 of suggested instructions, I get the following error msg:

    "X Failed to retrieve data for this request.(Microsoft.SqlServer.Management.Sdk.Sfc.)

    Additional information:

    an exception occurred while executing a Transact.Sql statement or batch(Microsoft.SqlServer.ConnectionInfo)

    C:\ProgramFiles\Microsoft SQL Server\MSSQL10.SLEXPRESS\MSSQL\DATA\Northwind.mdf is not a primary database file

    (Microsoft SQL Server, Error:5171)"

    120 pointsBadges:
    report
  • hunshabbir7
    Did you try to connect and query your data directly from SQL Server.
    If it is connecting and you can query your data then there might be some issue in your code. If you are not able to connect SQL Server then you need to see SQL Services if they are up and running.
    2,900 pointsBadges:
    report
  • mtboru
    I'll check into SQL Services to see if they're up. fyi, my connect attempt was via SQL Server.
    120 pointsBadges:
    report
  • carlosdl
    Sounds like your database file might be corrupt.  A file named Northwind.mdf looks to be a primary database file, so if it is not being recognized as one, it is most likely corrupt.

    Since this is a learning experience, you don't need to worry, but  one lesson you have to learn is that you need to take backups regularly, and specially before playing or experimenting with a database file.
    85,055 pointsBadges:
    report
  • mtboru

    Re the comment re SQL Services - I don't see anything in my SQL Server 2008 named such.

    Re the Northwind.mdb file possibly corrupted, I have yet to connect to it - at all. I'll see if the Book's problem's files contain one I can reload. I am concerned that the book indicates how to "grant access to this database file" via Properties within the DATA folder however I don't get access to the mentioned Security tab.

    120 pointsBadges:
    report
  • carlosdl

    The main problem is that most likely nobody trying to help you here  will have access to the book, so we don't have any idea of what it is telling you to do.


    I would recommend not trying to follow the book instructions like a recipe, but trying to understand the concepts and operations it teaches, so you can apply them on any database, knowing what you are doing.

    85,055 pointsBadges:
    report
  • hunshabbir7
    Exactly carlosdl, I was just commenting like you have. It seems not like a programmer attitude. If you are learning from scratch then you must understand the concepts. There might have many differences what your book is telling you and what is in your front. So don't be dis hurt and consult some other resources. 
    2,900 pointsBadges:
    report
  • mtboru
    Thanks "to all" for your suggestions. I'll get back into C# and cross the SQL bridge when I reach the point of having to build my own database. In the meantime, as I trudge thru the book's instructional chapters & code, I don't see any choice but to follow it's instructions explicitily in orrder to get the intended results.
    120 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: