将 ASPNETDB.mdf 上传到共享主机?
我正在开发 asp.net mvc2 应用程序,并且使用使用 ASPNETDB.mdf 数据库的 asp.net 会员提供程序。我也有自己的数据库,现在我想知道如何将这两个数据库上传到服务器?我应该将它们上传为 .mdf 文件还是应该使用 SQL Server?我更喜欢使用 SQL Server,如果有人知道转换和上传这两个数据库的最短方法,那将对我有很大帮助。
预先感谢,
伊利亚
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有趣的是我刚刚完成了同样的事情。基本步骤如下:
首先是成员资格提供者:
现在是角色提供者:
最后是 WebPart 提供程序(如果您使用它):
在此示例中,我将连接字符串称为
ConnectionStringLoginInfo
,但无论您如何命名它,请确保在连接字符串部分中设置它。我也不打算粘贴它:)这一切让我花费的时间比我想说的要多,但是当我看到我的应用程序在删除 App_Data 文件夹的情况下完美运行时,那是一个非常好的时刻!
Funny I just finished doing the same thing. The basic steps are as follows:
First the membership provider:
Now the role provider:
And lastly the WebPart provider, if you use it:
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!
对于托管解决方案(即您的托管计划不是虚拟专用服务器),最简单的选择是生成数据库的 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.
作为对 Blindy 答案的补充,我想提一下配置提供程序的另一种方法是更改大多数提供程序使用的默认 ConnectionString 的连接字符串设置,即 LocalSqlServer。为此,您只需覆盖 web.config 中的特定 ConnectionString,如下所示:
另外,如果您不想清除整个 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:
Also, if you don't want to clear the entire connectionStrings section you can just remove the particular connection string like this:
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