C# 获取平面文件连接的字段列表?
如何编写函数(外部函数、c#、f#或powershell脚本等)C# 获取平面文件连接的字段列表?,c#,sql-server,powershell,ssis,C#,Sql Server,Powershell,Ssis,如何编写函数(外部函数、c#、f#或powershell脚本等) List GetFields(string-ssisPackageName、string-fileSourceName); 要获取SSIS包的字段列表?由于包是一个Xml文件,可以使用xquery获取列表吗 或者更好的是,获取更多信息 class Field { public string Name { get; set; } public string Type { get; set; } } List<
List GetFields(string-ssisPackageName、string-fileSourceName);
要获取SSIS包的字段列表?由于包是一个Xml文件,可以使用xquery获取列表吗
或者更好的是,获取更多信息
class Field
{
public string Name { get; set; }
public string Type { get; set; }
}
List<Field> GetFields(string ssisPackageName, string fileSourceName);
类字段
{
公共字符串名称{get;set;}
公共字符串类型{get;set;}
}
列出GetFields(字符串ssisPackageName、字符串fileSourceName);
@billinkc是正确的,您应该记住数据键入问题。也就是说,您最多可以检索平面文件连接管理器本身的代码页和Unicode值。下面的代码应该让您开始,您可能需要查找代码页和数据类型属性
string path = @"MyPathTo\Package.dtsx";
XNamespace dts = "www.microsoft.com/SqlServer/Dts";
XDocument doc = XDocument.Load(path);
// get all connections
var connections = from ele in doc.Descendants(dts + "ConnectionManager")
where ele.Attributes(dts + "ObjectName").Count() != 0
select ele;
foreach (var connection in connections)
{
// look for your flat file connection
if (connection.Attribute(dts + "ObjectName").Value == "Flat File Connection Manager")
{
var connectionDetails = connection.Element(dts + "ObjectData").Element(dts + "ConnectionManager");
Console.WriteLine("CodePage: " + connectionDetails.Attribute(dts + "CodePage").Value);
Console.WriteLine("Unicode: " + connectionDetails.Attribute(dts + "Unicode").Value);
var columnList = connection.Descendants(dts + "FlatFileColumn");
foreach (var column in columnList)
{
Console.WriteLine("Column name: " + column.Attribute(dts + "ObjectName").Value);
Console.WriteLine("Column type: " + column.Attribute(dts + "DataType").Value);
}
}
}
需要检索特定平面文件连接管理器的列定义?我认为您的
字段
类不能充分表示数据类型的复杂性。如果是字符串,是ANSI还是Unicode?Unicode,8还是16?等
string path = @"MyPathTo\Package.dtsx";
XNamespace dts = "www.microsoft.com/SqlServer/Dts";
XDocument doc = XDocument.Load(path);
// get all connections
var connections = from ele in doc.Descendants(dts + "ConnectionManager")
where ele.Attributes(dts + "ObjectName").Count() != 0
select ele;
foreach (var connection in connections)
{
// look for your flat file connection
if (connection.Attribute(dts + "ObjectName").Value == "Flat File Connection Manager")
{
var connectionDetails = connection.Element(dts + "ObjectData").Element(dts + "ConnectionManager");
Console.WriteLine("CodePage: " + connectionDetails.Attribute(dts + "CodePage").Value);
Console.WriteLine("Unicode: " + connectionDetails.Attribute(dts + "Unicode").Value);
var columnList = connection.Descendants(dts + "FlatFileColumn");
foreach (var column in columnList)
{
Console.WriteLine("Column name: " + column.Attribute(dts + "ObjectName").Value);
Console.WriteLine("Column type: " + column.Attribute(dts + "DataType").Value);
}
}
}