コード例 #1
0
        /// <summary>
        /// Initializes the <see cref="Database"/> class.
        /// </summary>
        static KernelDatabase()
        {
            //string serverId = "tcp:degssql01.deg.local\\SQL2005";
            string serverId = "localhost\\sqlexpress";
            //string dbaseId = "NEUROX_sandbox";
            string userId   = "";
            string password = "";
            int    timeout  = 30;
            var    b        = new StringBuilder();

            SqlConnectionStringBuilder.AppendKeyValuePair(b, "data source", serverId);
            //SqlConnectionStringBuilder.AppendKeyValuePair(b, "initial catalog", dbaseId);
            SqlConnectionStringBuilder.AppendKeyValuePair(b, "persist security info", "false");
            SqlConnectionStringBuilder.AppendKeyValuePair(b, "timeout", timeout.ToString());
            if ((string.IsNullOrEmpty(userId)) && ((string.IsNullOrEmpty(password))))
            {
                SqlConnectionStringBuilder.AppendKeyValuePair(b, "integrated security", "true");
            }
            else
            {
                SqlConnectionStringBuilder.AppendKeyValuePair(b, "user id", userId);
                SqlConnectionStringBuilder.AppendKeyValuePair(b, "password", password);
                SqlConnectionStringBuilder.AppendKeyValuePair(b, "integrated security", "false");
            }
            s_connectionText = b.ToString();
        }
コード例 #2
0
        // mimicked after the getter from SqlConnectionStringBuilder.ConnectionString
        public static string ShortestConnectionString(SqlConnectionStringBuilder connectionStringBuilder)
        {
            string        result;
            StringBuilder builder = new StringBuilder();

            foreach (string key in connectionStringBuilder.Keys)
            {
                object valueObject;
                if (connectionStringBuilder.ShouldSerialize(key) && connectionStringBuilder.TryGetValue(key, out valueObject))
                {
                    string value        = (valueObject != null) ? Convert.ToString(valueObject, CultureInfo.InvariantCulture) : null;
                    string shortKey     = ShortestEquivalentKey(key);
                    bool   UseOdbcRules = false;
                    SqlConnectionStringBuilder.AppendKeyValuePair(builder, shortKey, value, UseOdbcRules);
                }
            }
            result = builder.ToString();
            return(result);
        }
コード例 #3
0
        public string GetConnectionString()
        {
            StringBuilder builder = new StringBuilder();

            SqlConnectionStringBuilder.AppendKeyValuePair(builder, "Server", Server);
            SqlConnectionStringBuilder.AppendKeyValuePair(builder, "Database", Database);

            if (!UseWindowsAuth)
            {
                SqlConnectionStringBuilder.AppendKeyValuePair(builder, "User Id", Username);
                SqlConnectionStringBuilder.AppendKeyValuePair(builder, "Password", Password);
            }
            else
            {
                SqlConnectionStringBuilder.AppendKeyValuePair(builder, "Trusted_Connection", "True");
            }

            return(builder.ToString());
        }