试图从c#应用程序调用R脚本

时间:2016-08-17 06:59:16

标签: c# r informix

Error in code
cmd result

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using RDotNet;
using Microsoft.Win32;
using System.IO;
using System.Diagnostics;

namespace Con_R2
{
    class Program
    {
        static string  rPath = "";

        static void Main(string[] args)
        {
            SetupPath(); // current process, soon to be deprecated
            using (REngine engine = REngine.CreateInstance("RDotNet"))
            {
                engine.Initialize(); // required since v1.5

                REngine.SetDllDirectory(rPath);

                foreach (string path in engine.Evaluate(".libPaths()").AsCharacter())
                {
                    Console.WriteLine(path);
                }
                engine.Evaluate(".libPaths(C:\\Program Files\\R\\R-3.3.1\\library)");
                engine.Evaluate("source('c:/Program Files/R/R-3.3.1/bin/clustering_loadprofiles.r')");

                Console.ReadLine();
                Console.ReadKey();
            }          
        }

        public static void SetupPath(string Rversion = "R-3.3.1")
        {
            var oldPath = System.Environment.GetEnvironmentVariable("PATH");
            rPath = System.Environment.Is64BitProcess ?
                                   string.Format(@"C:\Program Files\R\{0}\bin\x64", Rversion) :
                                   string.Format(@"C:\Program Files\R\{0}\bin\i386", Rversion);

            if (!Directory.Exists(rPath))
                throw new DirectoryNotFoundException(
                  string.Format(" R.dll not found in : {0}", rPath));
            var newPath = string.Format("{0}{1}{2}", rPath,
                                         System.IO.Path.PathSeparator, oldPath);
            System.Environment.SetEnvironmentVariable("PATH", newPath);
        }
    }
}

获取此错误

  

sqlFetch中出错(频道," sysadmin.loadprofile_allcustomers"):
  第一个参数不是开放的RODBC频道另外:警告   消息:1:在RODBC :: odbcDriverConnect(" DSN = informix116")中:   [RODBC]错误:状态IM014,代码0,消息[Microsoft] [ODBC驱动程序   经理]他指定DSN包含架构之间的不匹配   司机和应用2:在   RODBC :: odbcDriverConnect(" DSN = informix116"):ODBC连接失败

0 个答案:

没有答案