0

I am using the following tutorial example verbatim:

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx

The error message is that the connection failed. "Modify it to connect to a Norhtwinf=d database accessible to your system."

string connectionString =
     "Integrated Security=SSPI;Persist Security Info=False;" +
     "Initial Catalog=Northwind;Data Source=localhost";

SqlConnection northwindConnection = new SqlConnection(connectionString);
     northwindConnection.Open();

As far as Northwind Database, I downloaded it from this website and I ran it.

http://www.microsoft.com/download/en/details.aspx?id=23654

Would you be able to tell what am I doing wrong?

pnuts
  • 58,317
  • 11
  • 87
  • 139
user1298925
  • 2,304
  • 7
  • 29
  • 43
  • 3
    What is the error you are getting? – Justin Pihony Apr 04 '12 at 15:18
  • Can you add the full error message you are getting, to your question? – AdaTheDev Apr 04 '12 at 15:18
  • 2
    Have you setup SQL Server with the login details of the account running the application? – Oded Apr 04 '12 at 15:20
  • Also, make sure SQLServer is running. Right click my computer, go to manage and turn it on. – PaulG Apr 04 '12 at 15:21
  • Do you definitely have Northwind as a database in SQL Server Management studio? The sample you link is for SQL 2000 - I doubt that would automatically install itself into a more modern SQL Server. Which version are you running? Can you not download the sample databases for that? – Rup Apr 04 '12 at 15:21
  • You need to tell us what the the actual Exception you are getting. The error message you posted is not the actual exception. – iheartcsharp Apr 04 '12 at 15:22
  • Can you connect to the database using another program like Query Analyzer or the isql utility? – Adam Porad Apr 04 '12 at 15:24
  • @JUstin Pihony: The Connection String failed to Connect.Modify it to connect to a Norhtwind database accessible to your system. – user1298925 Apr 04 '12 at 15:47
  • @Oded: I guess that is my problem? I have no idea how to setup the demo database. – user1298925 Apr 04 '12 at 15:50
  • @PaulG: SQLEXPRESS has started. Do I need anything else? – user1298925 Apr 04 '12 at 15:51
  • @Rup: I am not sure. If you cn , give me a tutorial URL on what I need to do as I am new to Windows, Visual Studio 2010 , and SQL server but I am an experienced programmer. – user1298925 Apr 04 '12 at 15:54
  • @user78739: I tyoed the message for Justin Pihony – user1298925 Apr 04 '12 at 15:54
  • If you don't already have it you should download and install [SQL Server Management Studio Express](http://www.microsoft.com/download/en/details.aspx?id=7593) (that's the 2008 version). You can then use that to connect to your SQL Server and explore it, see which databases you have available etc. [According to this blog](http://blogs.msdn.com/b/smartclientdata/archive/2005/11/02/488258.aspx) the databases were installed as backup files; you should then use management studio to restore them into a new database (easier than the command line instructions there). – Rup Apr 04 '12 at 16:00

2 Answers2

1

Data Source property needs to point to your SQL instance name, and if your SQL instance is the default one.

I know that the next suggestion is a little weird and looks like the same that you are using, but try and let me know what happened:

string connectionString =
     "Integrated Security=SSPI;Persist Security Info=False;" +
     "Initial Catalog=Northwind;Data Source=.";

note that I've modified the Data Source value from 'localhost' to a (dot).

Mohammed Swillam
  • 9,119
  • 4
  • 36
  • 47
1

Make sure the account has access to that database, and try using this connection string:

connectionString="Server=MACHINE-NAME\SQLEXPRESS;Database=Northwind;Trusted_Connection=True;"
James Johnson
  • 45,496
  • 8
  • 73
  • 110