본문 바로가기
프로그래밍/ASP.NET

C# 바탕화면 파일 업로드시 `C:UsersseunggoDesktop1.sql` 경로에 대한 액세스가 거부되었습니다.' 에러

by Daily Investing 2012. 8. 28.
반응형

 //-- blob --//
        public void blob(DataRow dr, DataTable dtAttach)
        {
            for (int i = 0; i < dtAttach.Rows.Count; i++)
            {
                DataRow drAttach = dtAttach.Rows[i];

                FileStream fs = new FileStream(drAttach["FILE_PATH"].ToString(), FileMode.Open, FileAccess.Read);
                byte[] b = new byte[fs.Length - 1];
                fs.Read(b, 0, b.Length);
                fs.Close();

                string query = string.Empty;
                query = String.Concat(
                            "INSERT INTO UPLOAD_FILE                         \r\n"
                            , "     (PLANT, APPROVAL_NO, APPROVAL_SEQ, APPROVAL_TYPE, FILE_SEQ              \r\n"
                            , "      , FILE_TYPE, FILE_NAME, FILE_PATH, FILE_SIZE, FILE_DATA       \r\n"
                            , "     )                                   \r\n"
                            , "     VALUES ('" + dr["PLANT"].ToString() + "'                                \r\n"
                            , "             , '" + dr["APPROVAL_NO"].ToString() + "'          \r\n"
                            , "             , '" + dr["APPROVAL_SEQ"].ToString() + "'                       \r\n"
                            , "             , '" + dr["APPROVAL_TYPE"].ToString() + "'                      \r\n"
                            , "             , '" + drAttach["FILE_SEQ"].ToString() + "'                     \r\n"
                            , "             , '" + drAttach["FILE_TYPE"].ToString() + "'     \r\n"
                            , "             , '" + drAttach["FILE_NAME"].ToString() + "'                 \r\n"
                            , "             , '" + drAttach["FILE_PATH"].ToString() + "'        \r\n"
                            , "             , '" + b.Length + "'                                \r\n"
                            , "             , :file_data                                                 \r\n"
                            , "            )                      \r\n"
                            );

                int result = -1;

                string strTmp = DbManager.GetConnectionString();

                int n = strTmp.IndexOf(';');

                string strConn = strTmp.Substring(n + 1);

                //Provider=OraOLEDB.Oracle; Data Source=MYTMCM; User ID=MIGHTY; Password=MIGHTY;
                //string strConnection = "Data Source=MYTMCM; User ID=MIGHTY; Password=MIGHTY;";

                OracleCommand oleCmd = null;
                Oracle.DataAccess.Client.OracleParameter oracleParameter = null;

                using (OracleConnection conn = new OracleConnection(strConn))
                {
                    try
                    {
                        oleCmd = new OracleCommand(query, conn);

                        if (conn.State != ConnectionState.Open)
                        {
                            conn.Open();
                        }

                        oracleParameter = new Oracle.DataAccess.Client.OracleParameter();
                        oracleParameter.ParameterName = ":file_data";
                        oracleParameter.OracleDbType = OracleDbType.Blob;
                        oracleParameter.Direction = ParameterDirection.Input;
                        oracleParameter.Size = b.Length;
                        oracleParameter.Value = b;
                        oleCmd.Parameters.Add(oracleParameter);
                        result = oleCmd.ExecuteNonQuery();
                        oleCmd.Parameters.Clear();

                    }
                    catch (Exception ex)
                    {
                        QueryLogger.Log(this, ex.Message);
                        throw new Exception(ex.Message);
                    }
                    finally
                    {
                        if (oracleParameter != null) oracleParameter.Dispose();
                        if (oleCmd != null) oleCmd.Dispose();
                        if (conn != null) conn.Dispose();
                    }
                }
            }

        }

 

 

 

반응형