コード例 #1
0
        public static ActionResult SetApplicationReference(Session session)
        {
            try
            {
                session.Log("SetApplicationReference: Begin");

                var builder = new SqlConnectionStringBuilder(session["CONNECTION_STRING"]);


                using (var connection = new SqlConnection(builder.ConnectionString))
                {
                    ApplicationReference appref = new ApplicationReference();
                    appref.ApplicationInitPage     = "Home/Index";
                    appref.ApplicationOrDeviceType = "http://localhost/Moltu";
                    appref.ApplicationRootName     = "TasmusNetasMoltu";
                    SetApplicationRef(connection, appref);
                }

                session.Log("SetApplicationReference: End");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                session.Log("SetApplicationReference: exception: {0}", ex.Message);
                throw;
            }


            return(ActionResult.Success);
        }
コード例 #2
0
        private static void SetApplicationRef(SqlConnection conn, ApplicationReference appRef)
        {
            try
            {
                string selectSql = "SELECT * FROM ApplicationRef  WHERE ApplicationOrDeviceType='" + appRef.ApplicationOrDeviceType + "';";
                string deleteSql = string.Empty;
                string insertSql = string.Empty;

                SqlCommand command = new SqlCommand(selectSql, conn);
                command.Connection.Open();

                var reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    deleteSql = "DELETE  ApplicationRef WHERE ApplicationOrDeviceType='" + appRef.ApplicationOrDeviceType + "';";
                    command.Connection.Close();
                    command.CommandText = deleteSql;
                    command.Connection.Open();
                    command.ExecuteNonQuery();
                }

                insertSql = "INSERT INTO ApplicationRef (ApplicationOrDeviceType, ApplicationRootName,ApplicationInitPage) VALUES ('" + appRef.ApplicationOrDeviceType + "','" + appRef.ApplicationRootName + "','" + appRef.ApplicationInitPage + "')";
                command.Connection.Close();
                command.CommandText = insertSql;
                command.Connection.Open();
                command.ExecuteNonQuery();
                command.Connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
        public static ActionResult VerifySqlConnection(Session session)
        {
            try
            {
                //Debugger.Break();

                session.Log("VerifySqlConnection: Begin");

                var builder = new SqlConnectionStringBuilder
                {
                    DataSource     = session["DATABASE_SERVER"],
                    InitialCatalog = "Device",
                    ConnectTimeout = 5
                };

                if (session["DATABASE_LOGON_TYPE"] != "DatabaseIntegratedAuth")
                {
                    builder.UserID   = session["DATABASE_USERNAME"];
                    builder.Password = session["DATABASE_PASSWORD"];
                }
                else
                {
                    builder.IntegratedSecurity = true;
                }

                using (var connection = new SqlConnection(builder.ConnectionString))
                {
                    if (connection.CheckConnection(session))
                    {
                        session["ODBC_CONNECTION_ESTABLISHED"] = "1";
                        session["CONNECTION_STRING"]           = connection.ConnectionString;

                        ApplicationReference appref = new ApplicationReference();
                        appref.ApplicationInitPage     = "Home/Index";
                        appref.ApplicationOrDeviceType = "http://localhost/Moltu";
                        appref.ApplicationRootName     = "TasmusNetasMoltu";
                        SetApplicationRef(connection, appref);
                    }
                    else
                    {
                        session["ODBC_CONNECTION_ESTABLISHED"] = string.Empty;
                    }
                }

                session.Log("VerifySqlConnection: End");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                session.Log("VerifySqlConnection: exception: {0}", ex.Message);
                throw;
            }

            return(ActionResult.Success);
        }