Simple question on SQL connection string in VSO/C#

  • Thread starter Thread starter RandV80
  • Start date Start date
R

RandV80

Guest
Im just starting out on a project in VSO using C#, and have added a SQL DB into my project and am trying to connect to it. I have the following setup:

MySolution

-MyProject

--Program.cs

--<the other usual stuff>

--MyDB.mdf

--MyDBDataSet.xsd

Now what would the connection string be to connect to the DB in Program.cs?

SqlConnection conn = new SqlConnection();
conn.ConnectionString = "[???]";

try
{
conn.Open();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}

This is one of those things should be obvious but sometimes when youre starting out you cant quite find the right example. I the "Walkthrough: Creating a Local Database File in Visual Studio" guide from the MSDN library (wont let me directly link it yet) to create the local database file, but the next guide to connect to it uses a windows form project and provides no code, just GUI commands specific to a Windows Form project.

Any help would be appreciated, thanks.



Edit: I missed the sticky on my way in here, should this be moved to the SQL section?

Continue reading...
 
Back
Top