简体   繁体   English

通过web.config文件建立SQL Server 2008与VS2012项目的连接

[英]Establishing connection of SQL Server 2008 with VS2012 project via web.config file

I'm trying to connect my database from my SQL Server to my asp.net project through the web.config file. 我正在尝试通过web.config文件将数据库从SQL Server连接到asp.net项目。 I found code like this which should be able to connect my SQL Server and ASP.net project together properly. 我发现这样的代码应该可以将我的SQL Server和ASP.net项目正确地连接在一起。 However after adding this code, I got this error. 但是,添加此代码后,出现此错误。

This is my SQL Server connection string that is supposed to be place in web.config : 这是我的SQL Server连接字符串,应该放在web.config

<connectionStrings>
   <add name="MyConnectionString" 
        connectionString="Data Source=sergio-desktop\sqlexpress;Initial 
                          Catalog=MyDatabase;User ID=userName;Password=password"
        providerName="System.Data.SqlClient" />
</connectionStrings>

And this is the error 这是错误

在此处输入图片说明

I'm also not very sure if the syntax of my connection string to establish connection between the two is correct. 我也不太确定我用来建立两者之间连接的连接字符串的语法是否正确。

As the error suggests, the connection element should not go in system.web section. 如错误所示,连接元素不应放在system.web部分中。 it should go in configuration section of your web.config 它应该进入您的web.config configuration部分

as

<configuration>
<connectionStrings>
---

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 生成Web.config以将数据从文件加载到Visual Studio 2012中的MS SQL 2008服务器数据库 - generate Web.config for loading data from a file to MS SQL 2008 server database in Visual Studio 2012 使用 web.config 转换在 vs2012 中本地部署 - Local deploy in vs2012 using web.config transforms 无法连接到VS2012中的localDB - “建立与SQL Server的连接时发生与网络相关或特定于实例的错误...” - Unable to connect to localDB in VS2012 – “A network-related or instance-specific error occurred while establishing a connection to SQL Server…” 使用VS2012建立SQL连接和创建SQL命令的正确语法是什么? - What is the correct syntax for establishing an SQL connection and creating SQL Commands with VS2012? 与SQL Server 2008建立连接 - Establishing connection with SQL Server 2008 来自 web.config 文件的 SQL 连接 - SQL Connection from web.config file 存储在web.config文件中的连接字符串无法打开SQL Server连接 - Connection string stored in web.config file doesn't open SQL Server connection vs 2012 Web.Config转换 - vs 2012 Web.Config transformation VS 2008 中未定义的 Web.config 错误 - Undefined Web.config error in VS 2008 VS2012中的SQL Server项目 - SQL Server projects in VS2012
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM