0

提醒。所以这就是我到目前为止所得到的。我找到了一篇关于如何通过 Java 运行可执行文件的帖子。我使用了它并且 tablediff 实用程序正在运行。但我必须按照 SQL Server 的要求将参数传递给 tablediff 实用程序。

代码:

public static void main(String[] args) throws IOException

    {

        String sourceserver = "-sourceserver source_name";
        String sourcedatabase ="-sourcedatabase dbtest01";
        String sourcetable = "-sourcetable article";
        String destinationserver = "-destinationserver destination_name";
        String destinationdatabase ="-destinationdatabase dbtest02";
        String destinationtable = "-destinationtable article";

        Process process = new ProcessBuilder("C:\\Program Files\\Microsoft SQL Server\\110\\COM\\tablediff.exe",sourceserver,sourcedatabase,sourcetable,destinationserver,destinationdatabase,destinationtable).start();    

        InputStream is = process.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line;

        System.out.printf("Output of running %s is:", Arrays.toString(args));

        while ((line = br.readLine()) != null) 
        {
          System.out.println(line);
        }
    }

我不断收到此错误:

Output of running [] is:
Microsoft (R) SQL Server Replication Diff Tool 
Copyright (c) 2008 Microsoft Corporation

User-specified agent parameter values:
-sourceserver source_name 
The parameter '-sourceserver source_name' is invalid.

命令提示符像这样执行它:

C:\Program Files\Microsoft SQL Server\110\COM\>tablediff.exe -sourceserver source_name -sourcedatabase dbtest01 -sourcetab
le article -destinationserver destination_name -destinationdatabase dbtest02 -destin
ationtable article

Microsoft (R) SQL Server Replication Diff Tool
Copyright (c) 2008 Microsoft Corporation

User-specified agent parameter values:
-sourceserver source_name
-sourcedatabase dbtest01
-sourcetable article
-destinationserver destination_name
-destinationdatabase dbtest02
-destinationtable article

Table [dbtest01].[dbo].[article] on source_name and Table [dbtest02].[dbo].[art
icle] on destination_name have 1 differences.
Err     id
Dest. Only      N'004       '
The requested operation took 9.1819181 seconds.

我不知道为什么程序给出了无效的参数。我尝试将字符串更改为“source_name”等等。不工作。我还尝试将字符串直接传递给 Processbuilder。也不起作用。它给了我同样的错误信息。

4

1 回答 1

0

根据您的输入,我会说 source_name 和 destination_name 需要是您的数据库服务器的名称

String sourceserver = "-sourceserver source_name";
String destinationserver = "-destinationserver destination_name"; 

-sourceserver source_server_name[\instance_name] 是源服务器的名称。为 SQL Server 的默认实例指定 source_server_name。为 SQL Server 的命名实例指定 source_server_name\instance_name。

-destinationserver destination_server_name[\instance_name] 是目标服务器的名称。为 SQL Server 的默认实例指定 destination_server_name。为 SQL Server 的命名实例指定destination_server_name\instance_name。

编辑>>

你可以试试 -sourceserver \\MSSQLSERVER 我认为它可能是 \ 是并且为单个反斜杠转义所以你只是得到“\ MSSQLSERVER”

于 2013-06-26T06:59:44.403 回答