简体   繁体   中英

How to connect to SQL Server 2008 database at runtime in configuration file?

I'm trying to connect to SQL Server 2008 at runtime in a configuration file.

I'm only connect to SQL Server 2008 Express that built-in Visual Studio 2008.

Here is some code that I wrote

<add name="MyName" 
     connectionStrings="Data Source=.\sqlexpress;AttachDBFileName=|DataDirectory|\Database\mydatabase.mdf;Integrated Security=true;User Instance=true;" />

That code is to connect to SQL Server 2008 Express database.

I want to know which code can connect real SQL Server 2008 database instead of SQL Server Express...

Please answer me if you know... Always respects all of you...

Thanks..

Take a look at this link:

http://www.connectionstrings.com/sql-server-2008

It goes over the various ways you can setup your connection strings. Your "typical" connection string (if there is such a thing) will probably look something like this:

Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

But it really depends on how your SQL Server instance is configured and what kind of security you want to use.

If I'm using AD authentication, I go with

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

If SQL server auth, I use

Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM