gpt4 book ai didi

sql-server - 如何在没有 DSN 的情况下连接到 ColdFusion 7 中的 SQL Server?

转载 作者:行者123 更新时间:2023-12-03 16:40:28 24 4
gpt4 key购买 nike

我正在运行 Coldfusion MX 7 的服务器上编写 CFC。CFC 需要能够查询数据库,其位置将在运行时确定。数据库是 SQL Server 2005。CFC 将服务器的 IP 地址和数据库的名称作为参数,内置的 Windows 身份验证应该允许来自机器的连接。但是,我无法弄清楚如何对连接进行编码。自 CF5 以来, 标签不支持 connectstring 属性。设置系统 DSN 不够动态。我知道可能有一些方法可以在不使用 DSN 的情况下连接到 SQL Server,但目前我不知道该方法。有谁知道如何做到这一点?

最佳答案

您可以使用数据源服务修改 CF7 上的数据源。沿着这些方向的东西可能会起作用:

<cfset service = createobject("java","coldfusion.server.ServiceFactory").getDatasourceService()>
<cfset uname = "yourUserName">
<cfset pw = service.encryptPassword("yourPassword")>
<cfdump var="#createobject("java","coldfusion.server.ServiceFactory").getDatasourceService()#">
<cfset ds = service.getDatasources()>
<cfset dsn = "MyDSN">
<cfset thisDS = service.getDatasource(dsn)>
<cfset thisDS.getDatasourceDef().setPassword(pw)><!--- if you need to set the password programmatically --->
<!--- do stuff to set the URL... you can get the appropriate functions from the cfdump of the datasourceservice, above --->
Verifying datasource: #service.verifyDatasource(dsn)# <br>

关于sql-server - 如何在没有 DSN 的情况下连接到 ColdFusion 7 中的 SQL Server?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1982096/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com