ASP 到数据库的连接

发布于 2024-11-09 13:24:34 字数 111 浏览 0 评论 0原文

我是 ASP 新手。我有两个数据库生产数据库和开发人员数据库。
我需要检查开发者网站是否进入开发者数据库。两个数据库具有相同的数据和相同的表名。
但我必须只在开发人员数据库上工作,我该怎么办?

I am new to ASP. I have two databases production and developer databases.
I need to check developer site is going to developer database or not. Both databases have same data and same table names.
But i must work on developer database only how can I?

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

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

发布评论

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

评论(3

别靠近我心 2024-11-16 13:24:34

通常您会有一个环境配置文件。如果您谈论的是 ASP.NET,那么它就是 Web.config 文件。如果您确实谈论的是经典 ASP,那么它可能是包含一些常量的脚本。

如果数据库在结构上相同(它们应该是相同的),那么您需要更改的只是连接字符串。对于经典 ASP,您可能只需将其存储在变量中:

Dim connString = "This is your connection string"

在生产服务器上,连接字符串将设置为您的生产数据库。在开发机器上,它将被设置为开发数据库。 (对于测试环境等)所有数据访问代码都将仅使用此连接字符串变量。

更重要的是,这不应该是阻止开发人员使用生产数据库的唯一因素。 DBA 应设置权限,以便生产应用程序拥有该数据库所需的访问权限,而其他应用程序则没有。开发人员永远不应该意外修改生产数据库。因此,即使您确实使用了工作站中的生产连接字符串,数据库也应该简单地拒绝您的访问。

Generally you'd have an environment configuration file. If you're talking about ASP.NET then it would be the Web.config file. If you're indeed talking about classic ASP then it would probably be an included script with some constants.

If the databases are structurally identical (which they should be) then all you should need to change is the connection string. For classic ASP, you'd probably just store it in a variable:

Dim connString = "This is your connection string"

On the production server, the connection string would be set to your production database. On development machines, it would be set to a development database. (And so on for a test environment, etc.) All of the data access code would just use this connection string variable.

Even more to the point, this should not be the only thing that prevents a developer from using the production database. The DBA should set the permissions such that only the production application has only the access it needs to that database and others do not. Developers should never be able to accidentally modify the production database. So even if you did use the production connection string from your workstation, the database should simply deny you access.

疯狂的代价 2024-11-16 13:24:34

有两个连接字符串。然后创建一个常量变量,它将充当您的开关并选择正确的连接字符串:

Dim strCon
CONST DEVELOPMENT = true

if(DEVELOPMENT = true) then
    strCon = "Development connection string"
else
    strCon = "Live connection string"
end if

adoCon.open strCon

然后您可以简单地将开关更改为 true/false,具体取决于要选择的数据库。

Have two connection strings. Then create a constant variable which will act as your switch and pick the correct connection string:

Dim strCon
CONST DEVELOPMENT = true

if(DEVELOPMENT = true) then
    strCon = "Development connection string"
else
    strCon = "Live connection string"
end if

adoCon.open strCon

Then you can simply change the switch to true/false depending on which database to pick.

极度宠爱 2024-11-16 13:24:34

当您指定数据库连接时,您知道您指向哪里,因此这应该很简单。但在开发和生产中使用单独的登录可能是个好主意。

所以答案是,您应该使用配置文件中的连接字符串来获取您需要的内容:应正确设置“database =..”设置,并且您的问题已解决 为了获得额外的确定性,请使用不同的登录名,这在任何情况下都是推荐的案件。

您还可以使用服务器跟踪来监视活动,但这在多用户数据库上并不容易,并且只是一种诊断工具,而不是治疗方法。

When you specify the database connection you know where you are pointing, so this should be straightforward. But it might be a good idea to use separate logins on dev and production.

So the answer is that you should use the connectionstrings in the config files to get what you need: the "database =.." setting should be set correctly and your problem is aolvedsolved To get extra certainty use different logins, which is recommendable in any case.

you can also use server tracing to monitor activity, but it is not easy on a multi user database and is only a diagnostics tool, not a cure.

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