How to write connection string to sql server in Web.config

Hi Expert,

I wrote connect string doesn't work, the error said "Login failed for user"

<add name="SysDB" connectionString="Data Source=ZBL-LT\SQLEXPRESS;Initial Catalog=Student;Persist Security Info=True;" providerName="System.Data.SqlClient" />

Thanks in advance.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongCommented:
you probably need to specify an User Id and password when necessary. pls refer and try out the various connection string in this link:

SQL Server connection strings

in addition, if you're using any version of Visual Studio, you can using existing wizard of Connection object to create the connection string.

How to: Create Connections to SQL Server Databases
Vikas GargBusiness Intelligence DeveloperCommented:

You can try this

<add name="myConnectionString" connectionString="server=localhost;database=myDb;uid=myUser;password=myPass;" />

if you want to connect with username and password


    <add name="Dbconnection" connectionString="Server=localhost;Initial Catalog=OnlineShopping;Integrated Security=True"/>
  </connectionStrings >

If you wish for windows authentication
dshi15Author Commented:
Thank you for quick response:

I like to use windows authentication

I replaced Data Source by localhost.

 <add name="SysDB" connectionString="Data Source=localhost;Initial Catalog=student;Integrated Security=True  " />

But I got this error

"An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: 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)"

If i use  Data Source=ZBL-LT\SQLEXPRESS, it has Login failed error,

I attached a screen shot how open SSM and connect database, I didn't have password, after I click on 'connect button', it will open database.

Thank you, please give more advice.
Ryan ChongCommented:
tried this?
 <add name="SysDB" connectionString="Data Source=ZBL-LT\SQLEXPRESS;Initial Catalog=student;Integrated Security=SSPI;" />

Open in new window

How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dshi15Author Commented:
Thank you,

 <add name="SysDB" connectionString="Data Source=ZBL-LT\SQLEXPRESS;Initial Catalog=student;Integrated Security=SSPI;" />

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.