0

我从http://opendb.lightspeedsystems.com/contentupdate/database.htm下载了一个数据库,它是一个 zip 存档。无论如何我的问题是,有两个文件:virussignatures.datvirussignatures.fmt. 我听说我应该使用 BCP 将数据库提取为 SQL。的内容virussignatures.fmt是:

8.0
11
1    SQLCHAR       2    64      "~~~~~"            1     VirusName  SQL_Latin1_General_CP1_CI_AS
2    SQLCHAR       2    32      "~~~~~"            2     VirusType           SQL_Latin1_General_CP1_CI_AS
3    SQLCHAR       2    32      "~~~~~"            3     AppSig              SQL_Latin1_General_CP1_CI_AS
4    SQLINT        0    4       "~~~~~"            4     SigStart            ""
5    SQLINT        0    4       "~~~~~"            5     SigEnd              ""
6    SQLCHAR       2    1024    "~~~~~"            6     Signature           SQL_Latin1_General_CP1_CI_AS
7    SQLBIT        1    1       "~~~~~"            7     Test                ""
8    SQLINT        0    4       "~~~~~"            8     CategoryNumber      ""
9    SQLINT        0    4       "~~~~~"            9     SourceNumber        ""
10   SQLDATETIME   0    8       "~~~~~"            10    TransactionTime     ""
11   SQLCHAR       2    50      ""                 11    KBID                SQL_Latin1_General_CP1_CI_AS

我想将 virussignatures.dat 转换为 XML 或可理解的 TXT。

这可以使用 Vb.Net 完成吗?如果有怎么办?无论如何,如果不是,应该怎么做?

4

1 回答 1

1

记下您的 sqlserver 数据库在哪里(本地或服务器上)。我假设是本地的。如果您尚未安装 SqlServer,请下载SqlExpress。该版本确实带有所需的客户端工具

如果您没有数据库,请创建一个数据库,我假设它称为病毒签名。

创建此表(在(新)数据库的查询窗口中运行它)

CREATE TABLE [dbo].[Virusses](
  VirusName nvarchar(64) NULL,
  VirusType nvarchar(32) NULL,
  AppSig nvarchar(32) NULL,
  SigStart int NULL,
  SigEnd int NULL,
  Signature nvarchar(1024) null,
  Test bit null,
  CategoryNumber int null,
  SourceNumber int null,
  TransactionTime Datetime null,
  KBID nvarchar(50)
);
GO

在本地 sql db 中导入数据

bcp virussignatures.dbo.Virusses in virussignatures.dat -f virussignatures.fmt -T -S .

阅读:http: //msdn.microsoft.com/en-us/library/ms162802.aspx

或者从新查询(在 sql 管理工作室中单击您的数据库)

BULK INSERT 
    Virusses 
      FROM 'c:\where\ever\your\file\is\virussignatures.dat' 
      WITH 
        ( FORMATFILE = 'c:\where\ever\your\file\is\virussignatures.fmt' );
GO

现在您已准备好基于此 c# 示例编写 vb 程序来读取 DataSet 中的表并通过在 VB.NET 程序中实现以下代码来调用 WriteXml。

SqlCommand command = new SqlCommand();
command.CommandText = "SELECT * FROM Virussignature";
command.CommandType = CommandType.Text;
command.Connection = new SqlConnection("Your conect string here");
SqlDataAdapter da = new SqlDataAdapter(command); 
DataSet ds = new DataSet();
da.Fill(ds, "Virussignature");
StreamWriter xmlDoc = new StreamWriter("virus.xml"); 
ds.WriteXml(xmlDoc);
xmlDoc.Close();
于 2011-02-15T22:19:16.513 回答