ASP.NET SQL 提供程序

发布于 2024-09-04 02:21:45 字数 199 浏览 4 评论 0原文

我遇到问题了。当我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

み青杉依旧 2024-09-11 02:21:45

你指的是这个:
<添加名称=“应用程序服务”
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.

淡墨 2024-09-11 02:21:45

我刚刚遇到了类似的问题。我在 VS 2008 中创建了一个网站,想尝试 Web 部件。添加了一些到页面,然后开始获取:

SQLExpress 数据库文件自动创建错误:

连接字符串使用应用程序 App_Data 目录中的数据库位置指定本地 Sql Server Express 实例。

我运行 aspnet_regsql.exe(向导,位于 .Net Framework 文件夹中)来创建数据库,然后将连接字符串添加到 web.config:

<configuration>
    <connectionStrings>
        <add name="aspnet_membership" connectionString="Data Source=localhost; Initial Catalog=aspnetdb; Integrated Security=SSPI;"/>
    </connectionStrings>
</configuration>

然后我将其添加到 web.config:

<configuration>
  <system.web>
    <webParts>
      <personalization defaultProvider="SqlPersonalizationProvider">
        <providers>
          <add name="SqlPersonalizationProvider"
          type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider"
          connectionStringName="aspnet_membership"
          applicationName="/" />
        </providers>
        <authorization>
          <deny users="*" verbs="enterSharedScope" />
          <allow users="*" verbs="modifyState" />
        </authorization>
      </personalization>
    </webParts>
  </system.web>
</configuration>

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:

SQLExpress database file auto-creation error:

The connection string specifies a local Sql Server Express instance using a database >location within the applications App_Data directory.

I ran aspnet_regsql.exe (wizard, in .Net framework folder) to create the database and then I added a connection string to web.config:

<configuration>
    <connectionStrings>
        <add name="aspnet_membership" connectionString="Data Source=localhost; Initial Catalog=aspnetdb; Integrated Security=SSPI;"/>
    </connectionStrings>
</configuration>

Then I added this to web.config:

<configuration>
  <system.web>
    <webParts>
      <personalization defaultProvider="SqlPersonalizationProvider">
        <providers>
          <add name="SqlPersonalizationProvider"
          type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider"
          connectionStringName="aspnet_membership"
          applicationName="/" />
        </providers>
        <authorization>
          <deny users="*" verbs="enterSharedScope" />
          <allow users="*" verbs="modifyState" />
        </authorization>
      </personalization>
    </webParts>
  </system.web>
</configuration>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文