简体   繁体   中英

SQL Server Express connection string error

Trying to figure out the correct connection string for a SQL Server Express database. Trying to publish my app to IIS and test before publishing to my hosting site.

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

I started here and also used connectionstrings.com . I also started reading the deploy asp.net app using SQL Server Compact article here

Using this connection string

Data Source=.\\SQLExpress;AttachDbFilename=H:\DB\Guestbook.sdf;Integrated Security=True

I get the above error

This connection string

<add name="DefaultConnection" 
     connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI; database=Guestbook; AttachDBFilename=|DataDirectory|Guestbook.sdf" 
     providerName="System.Data.SqlClient" />` 

throws a trust level error. I've changed to medium and full and still get one of the two errors.

I've tried a variation of a few different strings with no luck.

Thanks

请验证SQL服务已在services.msc中启动,并使用具有主机名ej的完整实例:HOSTNAME \\ SQLEXPRESS

The file extension indicates that this is not a SQL Server Express database, so you must use:

Data Source=<Full path to file>

or

Data Source=|DataDirectory|Guestbook.sdf

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