anshuman

pi sdk unable to open a session on the pi server

Discussion created by anshuman on Apr 2, 2013
Latest reply on Apr 4, 2013 by Gregor

 

 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Data.OleDb;

namespace PIServicesWrapper.Controllers
{
    using PIServicesWrapper.Models;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Web.Http;
    using System.Data.OleDb;

    public class TagDataController : ApiController
    {

        private string connString = "Provider=PIOLEDB; Data Source=simplyfeye; Integrated Security=SSPI; User ID=piadmin; Password=;Log File=C:\\Temp\\Log\\PIOLEDB.log;";


        private OleDbCommand cmd;
        private OleDbConnection cnn;

        public IEnumerable<PIUnitTagOutputData> GetAllTagData(UnitTagParamsInput unitTagParamsInput)
        {
            if (unitTagParamsInput == null)
            {
                UnitTagParamsInput unitTagParamsInput0 = new UnitTagParamsInput { fromTime = "01-Mar-2003 17:12:00", toTime = "*", timeRange = "30", tagStr="('SINUSOID','BA:TEMP.1')" };
                unitTagParamsInput = unitTagParamsInput0;
            }

            string mystarttime = unitTagParamsInput.fromTime;
            string myendtime = unitTagParamsInput.toTime;
            string tagStr = unitTagParamsInput.tagStr;
            string timeRange = unitTagParamsInput.timeRange;
            List<PIUnitTagOutputData> outputItems = new List<PIUnitTagOutputData>();
            PIUnitTagOutputData tmpItem;
            string lineSpeedSql = string.Format("SELECT tag, time, value, status FROM piarchive..piinterp2 u WHERE u.tag IN " + tagStr + " AND u.time BETWEEN '" + mystarttime + "' AND '" + myendtime + "' AND u.timestep = '" + timeRange + "' AND u.value !=''");
            //string lineSpeedSql = string.Format("SELECT tag, time, value, status FROM piarchive..picomp2 u WHERE u.tag IN " + tagStr + " AND u.time BETWEEN '" + mystarttime + "' AND '" + myendtime + "' AND u.value !=''");

            cnn = new OleDbConnection(connString);
            cmd = new OleDbCommand();
            cmd.CommandTimeout = 5000;
            cmd.Connection = cnn;

            try
            {
                cnn.Open();
            }
            catch (Exception ex)
            {
                //could not connect to the pi server
                outputItems.Add(new PIUnitTagOutputData { tag = ex.Message, time = ex.Data.ToString(), value = ex.ToString(), status = "" });                // outputItems.Add(ex.StackTrace);

            }

            try
            {
                DateTime current = DateTime.Now;
                //get the line status (running or not)
                cmd.CommandText = lineSpeedSql;

                //cmd.CommandText = lineStatusSql;
                OleDbDataReader rdr = cmd.ExecuteReader();
                try
                {
                    while (rdr.Read())
                    {
                        //tmpItem = rdr.GetString(0).ToString() + "||||" + rdr.GetString(2).ToString() +"^^^^"+ rdr.GetString(3).ToString(); 
                        //Console.WriteLine(rdr.GetInt32(0) + ", " + rdr.GetString(1));
                        string tag = rdr.GetString(0);
                        string time = rdr.GetValue(1).ToString();
                        string value = rdr.GetValue(2).ToString();
                        string status = rdr.GetInt32(3).ToString();

                        tmpItem = new PIUnitTagOutputData { tag = tag, time = time, value = value, status = status };

                        outputItems.Add(tmpItem);

                    }
                }
                finally
                {
                 
                    // always call Close when done reading.
                    rdr.Close();
                    // always call Close when done reading.
                    cnn.Close();
                }

            }
            catch (Exception ex)
            {
               
            }
            return outputItems.ToArray();
        }
    }
}

 The above code works perfectly fine when I start debugging the code on MS Visual studio 2012 for web by clicking on the "firefox" button. This same code fails to connect to the pi server when I release the code by creating the zip archive and in the IIS manager, deploy this application using import mechanism.

 

 

 

I receive th following error:

 

 

 

PI SDK] Unable to open a session on a server. The user name and password may be incorrect.

 

 

 

The url : http://localhost:51820/api/tagData works fine in debug mode. but after depluoyment say on port 8091,

 

the url http://localhost:8091/api/tagData does not work.

 

 

 

I am also able to connect to the PI server througn PI OLEDB Snap-In utility with the same username:password pair [padmin:""]

Outcomes