无法确定URI的格式
本文关键字:格式 URI 无法确定 | 更新日期: 2023-09-27 18:13:10
我正在研究从考勤系统中获取考勤记录的应用程序,并将其放在访问文件中并上传到我的网站。它工作成功,但当我专注于其他屏幕在我的桌面,回到应用程序给出这个错误!"无效的URI:无法确定URI的格式"
这是代码:
public void BatchTransfert(zkemkeeper.CZKEMClass axCZKEM1, int index, BackgroundWorker worker, DoWorkEventArgs e)
{
string sdwEnrollNumber ="";
int idwEnrollNumber = 0;
int idwTMachineNumber = 0;
int idwEMachineNumber = 0;
int idwVerifyMode = 0;
int idwInOutMode = 0;
int idwYear = 0;
int idwMonth = 0;
int idwDay = 0;
int idwHour = 0;
int idwMinute = 0;
int idwSecond = 0;
int idwWorkcode = 0;
int idwWorkCode = 0;
int idwReserved = 0;
int idwErrorCode = 0;
int iGLCount = 0;
int iIndex = 0;
string time;
string pcTime = DateTime.Now.Year.ToString() + "-" + GetMonthName(DateTime.Now.Month).ToString() + "-" + DateTime.Now.Day.ToString() + " " + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString();
string userID;
int AttStat;
DataSet ds = new DataSet();
DataTable AttendanceLogs = new DataTable();
DataColumn USERID = new DataColumn();
USERID.DataType = System.Type.GetType("System.String");
USERID.ColumnName = "USERID";
DataColumn CHECKTIME = new DataColumn();
CHECKTIME.DataType = System.Type.GetType("System.String");
CHECKTIME.ColumnName = "CHECKTIME";
DataColumn CHECKTYPE = new DataColumn();
CHECKTYPE.DataType = System.Type.GetType("System.Int32");
CHECKTYPE.ColumnName = "CHECKTYPE";
AttendanceLogs.Columns.Add(USERID);
AttendanceLogs.Columns.Add(CHECKTIME);
AttendanceLogs.Columns.Add(CHECKTYPE);
ds.Tables.Add(AttendanceLogs);
string sqlOnlineUpdate = "";
string deviceIPAdress = "";
try
{
Cursor = Cursors.WaitCursor;
axCZKEM1.EnableDevice(iMachineNumber[index], false);//disable the device
if (axCZKEM1.ReadGeneralLogData(iMachineNumber[index]))//read all the attendance records to the memory
{
while (axCZKEM1.IsTFTMachine(iMachineNumber[index]) ?
axCZKEM1.SSR_GetGeneralLogData(iMachineNumber[index], out sdwEnrollNumber, out idwVerifyMode, out idwInOutMode, out idwYear, out idwMonth,
out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkCode) //TFt machine
:
axCZKEM1.GetGeneralLogData(iMachineNumber[index], ref idwTMachineNumber, ref idwEnrollNumber, ref idwEMachineNumber, ref idwVerifyMode,
ref idwInOutMode, ref idwYear, ref idwMonth, ref idwDay, ref idwHour, ref idwMinute)) //ref idwSecond ref idwWorkCode))
{
iGLCount++;
time = idwYear.ToString() + "-" + GetMonthName(idwMonth).ToString() + "-" + idwDay.ToString() + " " + idwHour.ToString() + ":" + idwMinute.ToString() + ":" + idwSecond.ToString();
pcTime = DateTime.Now.Year.ToString() + "-" + GetMonthName(DateTime.Now.Month).ToString() + "-" + DateTime.Now.Day.ToString() + " " + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString();
userID = axCZKEM1.IsTFTMachine(iMachineNumber[index]) ? sdwEnrollNumber : idwEnrollNumber.ToString();
AttStat = idwInOutMode;
DataRow newRow = AttendanceLogs.NewRow();
newRow["USERID"] = userID;
newRow["CHECKTIME"] = time;
newRow["CHECKTYPE"] = idwInOutMode;
AttendanceLogs.Rows.Add(newRow);
}
string filename = Application.StartupPath + "''config.txt";
Serializer serializeFromFile = new Serializer();
settings = serializeFromFile.DeSerializeObject(filename);
//axCZKEM1.Disconnect();
axCZKEM1.EnableDevice(iMachineNumber[index], true);//enable the device
if (AttendanceLogs.Rows.Count > 0)
{
int i = 0;
progressBar1.Enabled = true;
progressBar1.Maximum = AttendanceLogs.Rows.Count;
progressBar1.Visible = true;
labelProgress.Visible = true;
String connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + settings.localDBPath;
OleDbConnection conn = new OleDbConnection(connString);
conn.Open();
axCZKEM1.GetDeviceIP(iMachineNumber[index], ref deviceIPAdress);
string sqlSelect;
string queryString;
string onlineApp;
string urlAdress;
#region UploadData
foreach (DataRow row in AttendanceLogs.Rows)
{
try
{
if (worker.CancellationPending == true)
{
e.Cancel = true;
break;
}
else
{
i++;
progressBar1.Value = i;
//Connection Info for Local DB
sqlSelect = "Select * from CHECKINOUT WHERE USERID = " + row["USERID"] + " and CHECKTIME = #" + row["CHECKTIME"] + "# and CHECKTYPE = '" + row["CHECKTYPE"] + "'";
OleDbCommand cmd = new OleDbCommand(sqlSelect, conn);
OleDbDataReader dataReader = cmd.ExecuteReader();
//Saving in local Db
if (!dataReader.HasRows)
{
queryString = "userID=" + row["USERID"] + "&time=" + row["CHECKTIME"] + "&AttStat=" + row["CHECKTYPE"] + "&pcTime=" + pcTime + "&schoolID=" + schoolID + "&schoolName=" + schoolName + "&machineName=" + machineName;
onlineApp = settings.onlinURL + @"/Admin/HR/Attendance_UpdateData.ashx?" + queryString;
urlAdress = onlineApp;
Uri url = new Uri(urlAdress);
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);
webReq.Method = "Get";
HttpWebResponse myWebResponse = (HttpWebResponse)webReq.GetResponse();
if (myWebResponse.ContentLength == 7)
{
dataReader.Close();
string sqlUpdate = "INSERT INTO CHECKINOUT ( USERID, CHECKTIME, CHECKTYPE )"
+ "VALUES (" + row["USERID"] + ", #" + row["CHECKTIME"] + "#, " + row["CHECKTYPE"] + ")";
cmd.CommandText = sqlUpdate;
dataReader = cmd.ExecuteReader();
}
myWebResponse.Close();
}
labelProgress.Text = "Transfering data from device IP : " + deviceIPAdress + ".... " + progressBar1.Value.ToString() + " / " + progressBar1.Maximum.ToString(); //row["USERID"];
labelProgress.Refresh();
dataReader.Close();
dataReader.Dispose();
}
}
catch (SqlException sqlExp)
{
MessageBox.Show(sqlExp.Message);
EventLog.WriteEntry("User ID", sqlExp.Message, EventLogEntryType.Information, 15);
SendMail("School : " + machineName + " / 'Method Batch Down' Error in Online database Conn : " + sqlExp.Message + "'n" + "Sql Query : " + sqlOnlineUpdate);
}
catch (Exception exp)
{
MessageBox.Show("Herre Apear the Error!!!!!!!!" + exp.Message + " +" + exp.HelpLink);
EventLog.WriteEntry("RFID finger Print", exp.Message, EventLogEntryType.Information, 15);
SendMail("School : " + machineName + " / 'Method Batch Down' Error in Transfert Data : " + exp.Message + "'n" + "Sql Query : " + sqlOnlineUpdate);
}
}
#endregion
//conn.Close();
//conn.Dispose();
}
//objConn.Close();
}
else
{
Cursor = Cursors.Default;
axCZKEM1.GetLastError(ref idwErrorCode);
if (idwErrorCode != 0 && idwErrorCode != -2)
{
//MessageBox.Show("Reading data from terminal failed,ErrorCode: " + idwErrorCode.ToString(), "Error");
SendMail("Reading data from terminal failed, ErrorCode: " + idwErrorCode.ToString());
}
else
{
//SendMail("No data from terminal returns!, ErrorCode: " + idwErrorCode.ToString());
}
}
axCZKEM1.EnableDevice(iMachineNumber[index], true);
labelProgress.Visible = false;
progressBar1.Visible = false;
Cursor = Cursors.Default;
}
catch (SqlException sqlEx)
{
EventLog.WriteEntry("User ID", sqlEx.Message, EventLogEntryType.Information, 15);
SendMail("School : " + machineName + " / 'Method Batch Down' Error in Online database Conn : " + sqlEx.Message + "'n" + "Sql Query : " + sqlOnlineUpdate);
}
catch (Exception ex)
{
EventLog.WriteEntry("RFID finger Print", ex.Message, EventLogEntryType.Information, 15);
//SendMail("School : " + machineName + " / 'Method Batch Down' Error in Transfert Data : " + ex.Message + "'n" + "Sql Query : " + sqlOnlineUpdate);
}
}
序言编辑:
结果不是这些愚蠢的东西。实例化Uri
需要相应的方案。调用new Uri("example.com/path")
将导致此异常。相反,您应该呼叫new Uri("http://example.com/path")
。但是,如果这不是您遇到的问题,请继续……
我不知道这个错误在哪里发生,以提供更多的细节,但这意味着你需要在Uri
构造函数中指定UriKind
。例如,new Uri("/path")
可能会抛出一个错误,我指定new Uri("/path", UriKind.Relative)
,这样它就可以工作了。所以无论你在哪里确定错误的来源,或者无论你在哪里调用那个构造函数,都要加上它。
我看到你打电话来
Uri url = new Uri(urlAdress);
在一个点。我跟你打赌就是这样。只需在该参数中添加任何类型值urlAddress
是指(它来自您的配置文件,但它可能是UriKind.Absolute
),你会是金色的。