/// <summary>
        /// 
        /// </summary>
        /// <param name="lobSystem"></param>
        /// <returns></returns>
        public static Credentials GetCredentialsFromLobSystem(LobSystem lobSystem)
        {
            uint language = SPContext.Current.Web != null ? SPContext.Current.Web.Language : 1033;

            var sssId = "";
            var providerimplementation = "";

            foreach (Property prop in SqlHelper.GetLobSystemInstanceProperties(lobSystem))
            {
                if (prop.Name == "SsoApplicationId")
                    sssId = prop.Value.ToString();

                if (prop.Name == "SsoProviderImplementation")
                    providerimplementation = prop.Value.ToString();
            }

            if (String.IsNullOrEmpty(sssId))
            {
                var message = SPUtility.GetLocalizedString("$Resources:ExternalLookup_Helper_SecureStore", "Resources", language);
                throw new Exception(message);
            }

            if (String.IsNullOrEmpty(providerimplementation))
            {
                var message = SPUtility.GetLocalizedString("$Resources:ExternalLookup_Helper_Provider", "Resources", language);
                throw new Exception(message);
            }

            var credentials = new SecureStoreHelper(sssId, providerimplementation).GetCredentials();

            if (credentials == null)
            {
                var message = SPUtility.GetLocalizedString("$Resources:ExternalLookup_Helper_Credentials", "Resources", language);
                throw new NoNullAllowedException(message);
            }

            return credentials;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SaveDataSource(object sender, EventArgs e)
        {
            string title = Request.Form["title"];
            string type = Request.Form["dataType"];
            string server = Request.Form["url"];
            string database = Request.Form["database"];
            string sssId = Request.Form["secureStoreApplicationId"];
            const string providerImplementation =
                "Microsoft.Office.SecureStoreService.Server.SecureStoreProvider, " +
                "Microsoft.Office.SecureStoreService, " +
                "Version=14.0.0.0, Culture=neutral, " +
                "PublicKeyToken=71e9bce111e9429c";

            // the connection string must be conform to
            // Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
            // check out http://stackoverflow.com/questions/8243008/format-of-the-initialization-string-does-not-conform-to-specification-starting-a

            Credentials credentials = null;
            try
            {
                credentials = new SecureStoreHelper(sssId, providerImplementation).GetCredentials();
            }
            catch(Exception ex)
            {
                var message = SPUtility.GetLocalizedString("$Resources:ExternalLookup_Status_SecureStore_Credentials", "Resources", _language);
                Status.InnerHtml = HtmlHelper.CreateErrorString(message, ex);
            }

            var connectionString =
                String.Format("Server={0};Database={1};Integrated Security=SSPI;",
                server, database);

            if(credentials != null && ConnectionStringIsValid(credentials, connectionString))
            {
                try
                {
                    var lobSystem = Creator.CreateLobSystem(title, SystemType.Database);
                    var lobSystemInstance = Creator.CreateLobSystemInstance(lobSystem, server, database, sssId, providerImplementation);

                    if (lobSystem != null && lobSystemInstance != null)
                    {
                        Status.InnerHtml = "";
                        ListLobSystems();
                    }
                    else
                    {
                        var message = SPUtility.GetLocalizedString("$Resources:ExternalLookup_Status_DataSource_Create", "Resources", _language);
                        Status.InnerHtml = HtmlHelper.CreateErrorString(message, null);
                    }
                }
                catch(Exception ex)
                {
                    var message = SPUtility.GetLocalizedString("$Resources:ExternalLookup_Status_DataSource_Permissions", "Resources", _language);
                    Status.InnerHtml = HtmlHelper.CreateErrorString(message, ex);
                }
            }
        }