通过 Web 服务连接到 SQL Server 2005
Delphi 2010、dbExpress 和 SQL Server 2005 DB
我正在尝试使用 Delphi 2010 和 SQL Server 2005 DB 连接到 SQL Server 2005 DB。数据库快运。
如果我创建一个标准的delphi应用程序并对我的连接进行硬编码(它可以工作!):
procedure TForm1.Button1Click(Sender: TObject);
var
Conn: TSQLConnection;
begin
Conn:= TSQLConnection.Create(nil);
Conn.ConnectionName:= 'VPUCDS_VPN_SE01';
Conn.LoadParamsOnConnect := True;
Conn.LoginPrompt:=True;
try
Conn.Connected:= True;
if Conn.Connected then
ShowMessage('Connected!')
else
ShowMessage('NOT Connected!')
finally
Conn.Free;
end;
end;
所有ini文件和DLL都驻留在与我的可执行文件相同的文件夹中
,是的,我有DBXMsSQL和DBXMsSQL。 再次在uses子句中使用MidasLib
,如果它不是Web服务,它就可以工作!
但是,如果我随后将代码移至 Web 服务 CGI 模块:
function TTest.ConnectToDB: Boolean;stdcall;
var
Conn: TSQLConnection;
begin
Conn:= TSQLConnection.Create(nil);
Conn.ConnectionName:= 'VPUCDS_VPN_SE01';
Conn.LoadParamsOnConnect := True;
Conn.LoginPrompt:=True;
try
Conn.Connected:= True;
result:= Conn.Connected;
finally
Conn.Free;
end;
end;
谢谢
Delphi 2010, dbExpress, and SQL Server 2005 DB
I am trying to make a connection to a SQL Server 2005 DB using Delphi 2010 & DBExpress.
If I create a standard delphi application and hard code my connection (IT WORKS!):
procedure TForm1.Button1Click(Sender: TObject);
var
Conn: TSQLConnection;
begin
Conn:= TSQLConnection.Create(nil);
Conn.ConnectionName:= 'VPUCDS_VPN_SE01';
Conn.LoadParamsOnConnect := True;
Conn.LoginPrompt:=True;
try
Conn.Connected:= True;
if Conn.Connected then
ShowMessage('Connected!')
else
ShowMessage('NOT Connected!')
finally
Conn.Free;
end;
end;
All the ini files, and DLLs reside in the same folder as my executable
and yes, I have DBXMsSQL & MidasLib in the uses clause
again, it works if its not a web service!
However, if i then move the code over to a Web services CGI module:
function TTest.ConnectToDB: Boolean;stdcall;
var
Conn: TSQLConnection;
begin
Conn:= TSQLConnection.Create(nil);
Conn.ConnectionName:= 'VPUCDS_VPN_SE01';
Conn.LoadParamsOnConnect := True;
Conn.LoginPrompt:=True;
try
Conn.Connected:= True;
result:= Conn.Connected;
finally
Conn.Free;
end;
end;
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该线
是出现问题的第一个迹象。 Web 服务无法处理登录提示。
其次,VPUCDS_VPN_SE01在哪里定义的?如果它是用户特定的 ODBC 连接,则应将其设为系统范围的连接。
在连接定义中提供登录详细信息,并将 LoginPrompt 设置为 false。另外,提供一种方法将连接失败的原因返回给客户端(例如,通过传递异常消息)。
The line
is the first indication that something is wrong. A web service can not deal with a login prompt.
Second, where is VPUCDS_VPN_SE01 defined? If it is a user-specific ODBC connection, you should make it a system-wide connection.
Provide login details in the connection definition, and set LoginPrompt to false. Also, provide a way to return the cause of connection failure to the client (e.g. by passing the Exception's message).
我最近遇到了类似的情况,打印 QuickReports 在申请表中可以正常工作,但在切换到服务时却无法工作。这是在 Windows Server 2008 上。事实证明,需要使用“NetworkService”作为登录选项卡下的用户帐户来安装服务(在您的情况下为 WebServer)。来自 Windows 帮助:
为此,请转至“开始”->“运行”,然后输入 services.msc
导航到 IIS 服务,然后 输入右键单击并选择属性,然后转到登录。
确保选中此帐户并且显示网络服务
I recently came across a similar situation where printing QuickReports would work fine in application form but when switched to a service did not work. This was on Windows Server 2008. Turns out the service (in your case the WebServer) needed to be installed with "NetworkService" as the user account under the logon tab. From the Windows Help:
To do this go Start->Run and then enter services.msc
Navigate to the IIS service and right click and select Properties and then go to Log on.
Make sure This Account is checked and it says Network Service