I'm using MS Visual Studio 2010 to create an application with SQL Server 2008 database access, but what I did to create the database was add a new "SQL Server 2008 Database Project", it added it, and shows me everything on my Solution Explorer, but how do I write the connection string to connect to it, because I wrote this one, and it didn't work.
SqlConnection cnTrupp = new SqlConnection("Initial Catalog = Database;Data Source = localhost;Persist Security Info=True;");
update:
I used this one:
cnTrupp = new SqlConnection("database=DB_Trupp;server=.\\SQLExpress;Persist Security Info=True;integrated security=SSPI");
But when I use the cnTrupp.Open()
it tells me that the login failed.
Check out the connection strings web site which has tons of example for your connection strings.
Basically, you need three things:
.
" or (local)
or localhost
for the local machine)For example, if you want to connect to your local machine and the AdventureWorks
database using integrated security, use:
server=(local);database=AdventureWorks;integrated security=SSPI;
Or if you have SQL Server Express on your machine in the default installation, and you want to connect to the AdventureWorksLT2008 database, use this:
server=.\SQLExpress;database=AdventureWorksLT2008;integrated Security=SSPI;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With