Link to home
Start Free TrialLog in
Avatar of dshi15
dshi15Flag for United States of America

asked on

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.
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

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
http://www.connectionstrings.com/sql-server/

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
https://msdn.microsoft.com/en-us/library/s4yys16a(v=vs.90).aspx
SOLUTION
Avatar of Vikas Garg
Vikas Garg
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dshi15

ASKER

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.
Connection.docx
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dshi15

ASKER

Thank you,

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

works.