【发布时间】:2016-01-15 12:29:19
【问题描述】:
我有一堆带有查询的 sql 文件,每次这些文件发生一些更改时,这些文件不需要在我的本地数据库上运行。 我们使用经典的 ASP 代码在 VBScript 上编写的循环中运行这些文件,如下所示:
Dim arrSqlLines()
i = 0
set t = fso.OpenTextFile(filePath, 1, false)
Do Until t.AtEndOfStream
Redim Preserve arrSqlLines(i)
arrSqlLines(i) = t.ReadLine
i = i + 1
Loop
t.close
For Each sqlLine in arrSqlLines
sqlLine = Trim(sqlLine)
sqlBatch = Trim(sqlBatch & sqlLine) & vbCrLf
Call dbexecConnection(sqlBatch, objDbConnection)
Next
Function dbexecConnection(sql, objConnExec)
dim cmdTemp
on Error Resume Next
set cmdTemp=Server.CreateObject("ADODB.Command")
set cmdTemp.ActiveConnection=objConnExec
cmdTemp.CommandText = sql
cmdTemp.Execute
if err.number<>0 Then
if Session("SkipError") <> -1 Then
response.write "Error in dbexecute: " & sql & "<br/>"
response.write "Error=(" & err.description & ")"
response.End
end If
end If
on error goto 0
End Function
问题是,如果一个sql文件以UTF-8 without BOM编码,它运行正常,但是如果任何文件以UTF-8格式编码,它就会产生错误:
例如,这个非常 sql 文件的开头是这样的:
SET QUOTED_IDENTIFIER ON
GO
IF OBJECT_ID('RPM_GET_ACTUAL_COST_FOR_EPIC') IS NOT NULL
DROP Function [RPM_GET_ACTUAL_COST_FOR_EPIC]
GO
CREATE Function [RPM_GET_ACTUAL_COST_FOR_EPIC]
(
@EpicID as int,
@RateType as Int, -- 1 for Blended, 2 for CostCenter
@CalcType as Int -- 1 for by Hours or 2 for Points
)
returns float
BEGIN
declare @Cost float
declare @CostX float
declare @ItStorys TABLE (
StorylD int,
State int,
DemoStatus int,
Dfficulty int,
Feature int,
TeamID int,
TrackType int,
Iteration int
)
insert into @tStorys(StoryID, State, DemoStatus, Dfficulty, Feature, TeamID, TrackType, Iteration)
我不能保证所有文件都将以UTF-8 without BOM 编码,因此我必须找到使其正确运行的方法,以及UTF-8 文件。我怎么可能这样做?
【问题讨论】:
标签: sql-server encoding utf-8 vbscript asp-classic