Results 1 to 9 of 9

Thread: problem with connection strings

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Posts
    28

    problem with connection strings

    Hi

    I'm having problems with connection strings.

    I'm running a copy of vb express 2008 on my local. I also have installed a copy of sql on my local pc ( the sql version that comes with vb express 2008).

    I have written the following lines of code

    Imports System.Data
    Imports System.Data.SqlClient

    Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;" & _
    "Initial Catalog=northwnd")

    nwindConn.Open()

    the code compiles o.k but when i run it I get the error message :

    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 SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

    Does anyone know what causing the error?

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: problem with connection strings

    Thread moved to 'Database Development' forum

    It sounds like you are using SQL Server Express, in which case there is an instance name of SQLExpress, so you should add that:
    Code:
    "Data Source=localhost\SQLExpress;Integrated Security=SSPI;" & _

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Posts
    28

    Re: problem with connection strings

    hi,

    did what you suggested.

    now i get a different error message

    Cannot open database "northwind" requested by the login. The login failed. Login failed for user 'RAQIB-6D4CEC9C3\mohammed'.

    do you know what causes this error?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: problem with connection strings

    Was SQL Server Express installed under that user account or a different one? If it was a different one then that user account has probably not been added to the SQL Server Administrators group and will not be able to log in using Windows Security.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: problem with connection strings

    Isn't NorthWind an Access database?

    If so, then code for SQL Server (Imports System.Data.SqlClient
    and
    Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;" & _
    "Initial Catalog=northwnd")
    isn't going to work.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: problem with connection strings

    I'm pretty sure that there is also a Northwind for SQL Server now, so that people who are 'upsizing' can directly compare features etc to what is available in Access.

  7. #7
    Hyperactive Member
    Join Date
    May 2006
    Posts
    365

    Re: problem with connection strings

    Hello,

    I haven't used express edition but could you clarify what I suspect is a spelling mistake:
    Code:
    Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;" & _
    "Initial Catalog=northwnd")
    Kind regards

    Steve

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Aug 2007
    Posts
    28

    Re: problem with connection strings

    Hi,

    Threre are no accounts on my computer (When i start up the pc, there is no login prompt). I'm therefore assuming that the potential cause of the problem as suggested by jmcilhinney cannot be correct.

    I'm also certain that the spelling of the northwind database is correct. I have double checked this.

    Regards,
    Kareem.

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: problem with connection strings

    Whenever you are using Windows, you are always using an account. It sounds like you have got it set up to automatically log in to a particular account when Windows starts.

    Based on post #3, the account you are using is called "mohammed".

    Open up "SQL Server Management Studio" (or the interface inside VB), and check in the Security section that the account is listed there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width