简体   繁体   English

使用Perl无需使用ODBC DSN即可连接到MS SQL

[英]Using Perl to connect to MS SQL without use of an ODBC DSN

Is there a way to use Perl to connect to a MS SQL database without the use of ODBC? 有没有一种方法可以使用Perl而不使用ODBC连接到MS SQL数据库? I have a few scripts running in my production environment which I intend to migrate to perl. 我的生产环境中正在运行一些脚本,这些脚本打算迁移到perl。

Sample SQLCMD used: 使用的样本SQLCMD:

sqlcmd -S <dbHostName> -i <input_file> -o <output_file>

Sample BCP used: 使用的样本BCP:

bcp <sqlQuery> queryout <output_file> -c -t, -T -S <dbHostName>

The main reason is that I do not know the password to my production database, and I cannot have knowledge of it. 主要原因是我不知道生产数据库的密码,并且我不知道该密码。 Therefore there is no way I can pass in the pass phrase whether in my perl script or via the ODBC setup. 因此,无论是在我的perl脚本中还是通过ODBC设置,我都无法传递密码短语。

I notice that your sqlcmd statement does not include -U and -P . 我注意到您的sqlcmd语句不包含-U-P This means it is using the logged-in user's credentials to access the database. 这意味着它正在使用登录用户的凭据来访问数据库。

To accomplish the same with ODBC & DBI, include Trusted_Connection=True; 要使用ODBC和DBI完成相同的操作,请包括Trusted_Connection=True; in the connection string. 在连接字符串中。 This is akin to using the "With Windows NT authentication using the network login ID." 这类似于使用“使用Windows NT身份验证使用网络登录ID”。 radio button on the 2nd page of the DSN setup wizard. DSN设置向导第二页上的单选按钮。

For example on my Win 8.1 box, where SQL Server is the name of the relevant driver (not DSN) in my ODBC Data Source Administration interface, I might give the DBI connect method the following string: 例如,在我的Win 8.1框中,其中SQL Server是ODBC数据源管理界面中相关驱动程序 (不是DSN)的名称,我可以为DBI connect方法指定以下字符串:

dbi:ODBC:Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Trusted_Connection=True; dbi:ODBC:Driver = {SQL Server};服务器= myServerAddress;数据库= myDataBase; Trusted_Connection = True;

In contrast a string using a DSN might look like: 相反,使用DSN的字符串可能类似于:

dbi:ODBC:myDSN dbi:ODBC:myDSN

FWIW: I find http://connectionstrings.com to be a valuable resource. FWIW:我发现http://connectionstrings.com是有价值的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM