当前上下文中不存在名称 'fileName' - BIML
The name 'fileName' does not exist in the current context - BIML
我有一个受 this post 启发的 BIML 文件。
但是,我收到一个错误:
Error 0 The name 'fileName' does not exist in the current context. (32,16`)
我觉得我遗漏了一些非常明显的东西。
我在 VS 2019 + SSDT
和 BIML Express
中是 运行(目前都是最新版本)
我正在和
通话
Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64)
Aug 22 2017 17:04:49
Copyright (C) 2017 Microsoft Corporation
Developer Edition (64-bit) on Windows Server 2019 Standard 10.0 <X64> (Build 17763: ) (Hypervisor)
这是我的 BIML 代码:
<#@ template language="C#" hostspecific="true"#>
<#@ import namespace="System.IO"#>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<#
string Prefix="import";
// the locatie of the csv's'
string path = @"C:\test";
// Put all the filenames with the extension csv in a string array
string[] myFiles = Directory.GetFiles(path, "*.csv");
// string that will be filled with the filename
string filename;
// string array for columnnames extracted from CSV
string[] myColumns;
#>
<Connections>
<OleDbConnection
Name="OLEDB_STG_<#=Prefix#>"
ConnectionString="Data Source=SQLSERVER;Initial Catalog=TEST;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;">
</OleDbConnection>
</Connections>
<Databases>
<Database ConnectionName="OLEDB_STG_<#=Prefix#>" Name="TEST"/>
</Databases>
<Schemas>
<Schema Name="dbo" DatabaseName="TEST" Owner="dbo"/>
</Schemas>
<Tables>
<!-- loop trough the array of files-->
<# foreach(string filePath in myFiles)
{
// extract the filename from the path to use as tablename
fileName = Path.GetFileNameWithoutExtension(filePath);
#>
<Table Name="<#=Prefix#>_<#=fileName#>" SchemaName="TEST.dbo">
<Columns>
<!-- loop trough the file looking for the columnnames-->
<#
// read first row of csv to extract to columnnames
// and split on comma to create an array
StreamReader myFile = new StreamReader(filePath);
myColumns = myFile.ReadLine().Split(',');
// close file after reading first line
myFile.Close();
// Loop through column array
foreach(string myColumn in myColumns)
{
#>
<Column Name="<#=myColumn#>" DataType="String" Length="255"></Column>
<# } #>
</Columns>
</Table>
<# }#>
</Tables>
</Biml>
C# 是区分大小写的语言,因此 filename
与 fileName
引用的变量不同,即它们不匹配:
string filename;
fileName = Path.GetFileNameWithoutExtension(filePath);
与所有 XML 一样,BIML 区分大小写。
包括复数集合在内的所有 Biml 对象都区分大小写。
// string that will be filled with the filename
string fileName;
{ // extract the filename from the path to use as tablename
fileName = Path.GetFileNameWithoutExtension(filePath); #> }
我有一个受 this post 启发的 BIML 文件。
但是,我收到一个错误:
Error 0 The name 'fileName' does not exist in the current context. (32,16`)
我觉得我遗漏了一些非常明显的东西。
我在 VS 2019 + SSDT
和 BIML Express
中是 运行(目前都是最新版本)
我正在和
Microsoft SQL Server 2017 (RTM) - 14.0.1000.169 (X64)
Aug 22 2017 17:04:49
Copyright (C) 2017 Microsoft Corporation
Developer Edition (64-bit) on Windows Server 2019 Standard 10.0 <X64> (Build 17763: ) (Hypervisor)
这是我的 BIML 代码:
<#@ template language="C#" hostspecific="true"#>
<#@ import namespace="System.IO"#>
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<#
string Prefix="import";
// the locatie of the csv's'
string path = @"C:\test";
// Put all the filenames with the extension csv in a string array
string[] myFiles = Directory.GetFiles(path, "*.csv");
// string that will be filled with the filename
string filename;
// string array for columnnames extracted from CSV
string[] myColumns;
#>
<Connections>
<OleDbConnection
Name="OLEDB_STG_<#=Prefix#>"
ConnectionString="Data Source=SQLSERVER;Initial Catalog=TEST;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;">
</OleDbConnection>
</Connections>
<Databases>
<Database ConnectionName="OLEDB_STG_<#=Prefix#>" Name="TEST"/>
</Databases>
<Schemas>
<Schema Name="dbo" DatabaseName="TEST" Owner="dbo"/>
</Schemas>
<Tables>
<!-- loop trough the array of files-->
<# foreach(string filePath in myFiles)
{
// extract the filename from the path to use as tablename
fileName = Path.GetFileNameWithoutExtension(filePath);
#>
<Table Name="<#=Prefix#>_<#=fileName#>" SchemaName="TEST.dbo">
<Columns>
<!-- loop trough the file looking for the columnnames-->
<#
// read first row of csv to extract to columnnames
// and split on comma to create an array
StreamReader myFile = new StreamReader(filePath);
myColumns = myFile.ReadLine().Split(',');
// close file after reading first line
myFile.Close();
// Loop through column array
foreach(string myColumn in myColumns)
{
#>
<Column Name="<#=myColumn#>" DataType="String" Length="255"></Column>
<# } #>
</Columns>
</Table>
<# }#>
</Tables>
</Biml>
C# 是区分大小写的语言,因此 filename
与 fileName
引用的变量不同,即它们不匹配:
string filename;
fileName = Path.GetFileNameWithoutExtension(filePath);
与所有 XML 一样,BIML 区分大小写。 包括复数集合在内的所有 Biml 对象都区分大小写。
// string that will be filled with the filename
string fileName;
{ // extract the filename from the path to use as tablename
fileName = Path.GetFileNameWithoutExtension(filePath); #> }