Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
242 views
in Technique[技术] by (71.8m points)

c# - Cannot connect to SQL Server database from VS2019 on my ASP.Net project

I have been trying to open my SQL Server database in Server Explorer, and I'm always getting the following error

Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement. This could be because the pre-login handshake failed or the server was unable to respond back in time. The duration spent while attempting to connect to this server was -[Pre-Login] initialization=18214; handshake=118555;

I've tried to fix the issue by repairing the VS2019, and that didn't work.

Edit: The database is running locally from my PC. And this is the connection string from Web.config file:

<add name="UserEntities" connectionString="metadata=res://*/Models.UsersModel.csdl|res://*/Models.UsersModel.ssdl|res://*/Models.UsersModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=Mizile;initial catalog=Login;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
question from:https://stackoverflow.com/questions/65645509/cannot-connect-to-sql-server-database-from-vs2019-on-my-asp-net-project

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're connection string is incorrect. If SQL Server is on your machine locally, or on your network then it CAN look something like this,

<add name="UserEntities" connectionString="Data Source=YourSqlInstanceName;Initial Catalog=YourDatabaseName;Integrated Security=True" providerName="System.Data.SqlClient" />

You can of course read MS docs about different types too.

https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/creating-a-connection-string


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...