将 ASPNETDB.mdf 上传到共享主机?

发布于 2024-10-07 19:04:45 字数 211 浏览 2 评论 0 原文

我正在开发 asp.net mvc2 应用程序,并且使用使用 ASPNETDB.mdf 数据库的 asp.net 会员提供程序。我也有自己的数据库,现在我想知道如何将这两个数据库上传到服务器?我应该将它们上传为 .mdf 文件还是应该使用 SQL Server?我更喜欢使用 SQL Server,如果有人知道转换和上传这两个数据库的最短方法,那将对我有很大帮助。

预先感谢,
伊利亚

I am developing asp.net mvc2 application and I use asp.net membership provider which uses ASPNETDB.mdf database. I have also my own database and now I wonder how to upload these 2 databases to server? Should I upload them as .mdf file or should I use SQL server? I prefer using SQL server and if someone knows the shortest way to convert and upload these 2 databases it would help me a lot.

Thanks in advance,
Ilija

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

单身狗的梦 2024-10-14 19:04:45

有趣的是我刚刚完成了同样的事情。基本步骤如下:

  1. 从 Visual Studio 中加载 .mdf 并选择“发布到提供程序”以创建 .sql 文件。
  2. 打开 SQL Management Studio,打开与数据库的连接并加载 sql 文件。添加“use yourdbname;”在顶部让它将表输出到您的数据库,然后运行它。
  3. 现在您应该拥有完整的表结构。剩下的就是修改 web.config 以读取新表:

首先是成员资格提供者:

<会员身份>;
  <提供商>
    <清除>>
    <添加名称=“AspNetSqlMembershipProvider”
         类型 =“System.Web.Security.SqlMembershipProvider,System.Web,版本=2.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a”
         连接字符串名称=“连接字符串登录信息”
         启用密码检索=“假”
         启用密码重置=“真”
         需要问题和答案=“假”
         需要UniqueEmail =“假”
         密码格式=“散列”
         maxInvalidPasswordAttempts =“5”
         minRequiredPasswordLength =“6”
         minRequiredNonalphanumericCharacters =“0”
         密码尝试窗口=“10”
         密码强度正则表达式=""
         应用程序名称=“/”
            >>
  

现在是角色提供者:


  <提供商>
    <清除>>
    <添加名称=“AspNetSqlRoleProvider”
         类型 =“System.Web.Security.SqlRoleProvider,System.Web,版本=2.0.0.0,文化=中性,PublicKeyToken=b03f5f7f11d50a3a”
         连接字符串名称=“连接字符串登录信息”
         应用程序名称=“/”
            >>
  

最后是 WebPart 提供程序(如果您使用它):

;
  <个性化defaultProvider =“SqlDatabaseProviderDRDBLoginInfo”>
    <提供商>
      <清除>>
      <添加连接字符串名称=“ConnectionStringLoginInfo”

           类型=“System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider”
           名称=“SqlDatabaseProviderDRDBLoginInfo”/>
    
  

在此示例中,我将连接字符串称为 ConnectionStringLoginInfo,但无论您如何命名它,请确保在连接字符串部分中设置它。我也不打算粘贴它:)

这一切让我花费的时间比我想说的要多,但是当我看到我的应用程序在删除 App_Data 文件夹的情况下完美运行时,那是一个非常好的时刻!

Funny I just finished doing the same thing. The basic steps are as follows:

  1. From Visual Studio, load your .mdf and choose "publish to provider" to make a .sql file.
  2. Open SQL Management Studio, open a connection to your database and load the sql file. Add a "use yourdbname;" on top to have it output the tables to your database, then run it.
  3. Now you should have the full table structure. What's left is to modify web.config to read the new tables:

First the membership provider:

<membership>
  <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider"
         type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a "
         connectionStringName="ConnectionStringLoginInfo"
         enablePasswordRetrieval="false"
         enablePasswordReset="true"
         requiresQuestionAndAnswer="false"
         requiresUniqueEmail="false"
         passwordFormat="Hashed"
         maxInvalidPasswordAttempts="5"
         minRequiredPasswordLength="6"
         minRequiredNonalphanumericCharacters="0"
         passwordAttemptWindow="10"
         passwordStrengthRegularExpression=""
         applicationName="/"
            />
  </providers>
</membership>

Now the role provider:

<roleManager enabled="true">
  <providers>
    <clear/>
    <add name="AspNetSqlRoleProvider"
         type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0,  Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a "
         connectionStringName="ConnectionStringLoginInfo"
         applicationName="/"
            />
  </providers>
</roleManager>

And lastly the WebPart provider, if you use it:

<webParts>
  <personalization defaultProvider="SqlDatabaseProviderDRDBLoginInfo">
    <providers>
      <clear/>
      <add connectionStringName="ConnectionStringLoginInfo"

           type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider"
           name="SqlDatabaseProviderDRDBLoginInfo"/>
    </providers>
  </personalization>
</webParts>

In this example I called the connection string ConnectionStringLoginInfo, but whatever you name it, make sure you set it in the connection strings part. Not gonna paste that too :)

This all took me way more than I care to say, but when I saw my app working flawlessly with the App_Data folder deleted, that was quite the moment!

醉态萌生 2024-10-14 19:04:45

对于托管解决方案(即您的托管计划不是虚拟专用服务器),最简单的选择是生成数据库的 SQL 脚本,将这些脚本导出到 *.sql 文件,然后在托管 SQL 连接中运行它们。

我通常会使用 SQL Server Management Studio 连接到我的 Web 主机的 SQL 实例,然后打开或粘贴由本地副本生成的脚本。

根据您的 Web 主机是否提供服务,您也许还可以使用 Visual Studio 中的“发布到提供商...”选项。

Your simplest option for a hosted solution (i.e. your hosting plan is not a Virtual Private Server) is to generate SQL scripts of your database, exporting these to *.sql files and then run them in your hosted SQL connection.

I would normally connect to my web host's SQL instance using SQL Server Management Studio and either open or paste in the scripts generated by my local copy.

Depending on whether or not your web host provides the service, you might also be able to use the "Publish to provider..." option in Visual Studio.

初懵 2024-10-14 19:04:45

作为对 Blindy 答案的补充,我想提一下配置提供程序的另一种方法是更改​​大多数提供程序使用的默认 ConnectionString 的连接字符串设置,即 LocalSqlServer。为此,您只需覆盖 web.config 中的特定 ConnectionString,如下所示:

<connectionStrings>
    <clear />
    <add name="LocalSqlServer" connectionString="change this to be the details of your host database" providerName="System.Data.SqlClient" />
</connectionStrings>

另外,如果您不想清除整个 connectionStrings 部分,您可以像这样删除特定的连接字符串:

<connectionStrings>
    <remove name="LocalSqlServer" />
    <add name="LocalSqlServer" connectionString="change this to be the details of your host database" providerName="System.Data.SqlClient" />
</connectionStrings>

这有效,因为默认的所有提供程序使用 Sql Server 作为数据存储(例如成员资格提供程序)时,默认情况下使用“LocalSqlServer”连接字符串。因此,如果您覆盖它,则不必更改每个提供程序以指向不同的连接字符串。

另外,出于安全原因,您可能需要考虑对 web.config 文件的 connectionString 部分进行加密。以下两篇文章提供了更多信息。

加密和解密配置节

如何:使用 RSA 加密 ASP.NET 2.0 中的配置节

As a supplement to Blindy's answer I wanted to mention that another way to configure the providers is to change the connection string settings of the default ConnectionString used by most of the providers, which is LocalSqlServer. To do this you just override that particular ConnectionString in your web.config like so:

<connectionStrings>
    <clear />
    <add name="LocalSqlServer" connectionString="change this to be the details of your host database" providerName="System.Data.SqlClient" />
</connectionStrings>

Also, if you don't want to clear the entire connectionStrings section you can just remove the particular connection string like this:

<connectionStrings>
    <remove name="LocalSqlServer" />
    <add name="LocalSqlServer" connectionString="change this to be the details of your host database" providerName="System.Data.SqlClient" />
</connectionStrings>

This works, because all providers that default to using Sql Server for their Data Store - such as the membership provider - use the "LocalSqlServer" connection string by default. Thus, if you override it, you don't have to change each provider to point to a different Connection String.

Also, for security reasons, you might want to look into encrypting the connectionString section of your web.config file. The following two articles provide more info.

Encrypting and Decrypting Configuration Sections

How To: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文