ASP.NET SQL 提供程序
我遇到问题了。当我使用 VS 2010 在 ASP.NET 中创建新项目时,它的 web.config 带有创建的有关 SQL Express 的默认连接字符串。但我什至还没有安装 SQL Express。我应该如何更改默认的 AspNetSqlProvider 以将我的全权 SQL Server 实例作为服务数据库使用?如何更改 ASP.NET 项目的模板以使用我的连接创建项目?
I got a problem. When i'm creating the new project in ASP.NET using VS 2010, it's web.config with a default connection string about SQL Express created. But i haven't even got SQL Express installed. What should i do to change the default AspNetSqlProvider to work with my instance of full-weight SQL Server as a services database? And how can i change the template for the ASP.NET project to create a project with my connection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你指的是这个:
<添加名称=“应用程序服务”
connectionString="数据源=.\SQLEXPRESS;集成安全性=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;用户实例=true"
providerName="System.Data.SqlClient" />
要将其更改为可与 SQL Server 一起使用的名称,它需要看起来更像这样:
<添加名称=“应用程序服务”
connectionString="数据源=服务器名称;初始目录=数据库名称"
providerName="System.Data.SqlClient" />
其中 DatabaseName可能是 aspnetdb。它需要某种形式的身份验证,无论您使用 Windows 身份验证(在这种情况下,您可以从原始连接字符串复制集成安全性元素)还是 SQL Server 身份验证(您将拥有一个用户名) /密码组合)。
connectionstrings.com 提供了有关构建连接字符串的大量信息。
要为您未来的项目修复此问题,您需要更改 Web 项目的模板。找到保存 C# Web 模板的文件夹(对我来说,这是
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\CSharp\Web\1033
。获取 WebApplicationProject40.zip 文件的副本(您可能还想将原始文件备份到某处!)。
在其中您将找到带有 SQL Express 连接字符串的 web.config 文件。将其更改为 SQL Server 字符串,然后重新组装 zip 文件。
最后一步是重建 VS 模板缓存 - 从命令行(VS 命令提示符可能效果最好)运行
devenv /installvstemplates
。有关详细信息,请参阅此处。You mean this one:
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
To change this into one that'll work with SQL Server, it needs to look more like this:
<add name="ApplicationServices"
connectionString="data source=ServerName;Initial Catalog=DatabaseName"
providerName="System.Data.SqlClient" />
where DatabaseName is probably aspnetdb. It'll need some form of authentication, whether you use Windows authentication (in which case you can copy the
Integrated Security
element from the original connection string) or SQL Server authentication (where you'll have a username/password combination).There's great info on building connection strings at connectionstrings.com.
To fix this for your future projects, you'll need to change the template for Web Projects. Locate the folder where your C# Web templates are kept (for me this is
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\CSharp\Web\1033
.Take a copy of the WebApplicationProject40.zip file (you might also want to backup the original somewhere!).
Inside it you'll find the web.config file with the SQL Express connection string. Change it to a SQL Server string, and then re-assemble the zip file.
The last step is to rebuild the VS template cache - from a command-line (VS Command Prompt probably works best), run
devenv /installvstemplates
. See here for details.我刚刚遇到了类似的问题。我在 VS 2008 中创建了一个网站,想尝试 Web 部件。添加了一些到页面,然后开始获取:
我运行 aspnet_regsql.exe(向导,位于 .Net Framework 文件夹中)来创建数据库,然后将连接字符串添加到 web.config:
然后我将其添加到 web.config:
I just had a similar problem. I had a web site created in VS 2008 and wanted to try web parts. Added some to a page, then started getting:
I ran aspnet_regsql.exe (wizard, in .Net framework folder) to create the database and then I added a connection string to web.config:
Then I added this to web.config: