Example #1
0
        /// <summary>
        /// Initializes a new instance of the SqlServer class.
        /// </summary>
        /// <param name="name">The name of the server (e.g. localhost)</param>
        /// <param name="username">The username to connect with</param>
        /// <param name="password">The password to connect with</param>
        /// <param name="useIntegrated"></param>
        public SqlServer(string name, string username, string password, bool useIntegrated)
        {
            string domain   = null;
            string userName = null;

            this.name               = name;
            this.username           = username;
            this.password           = password;
            this.IntegratedSecurity = useIntegrated;

            if (this.IntegratedSecurity)
            {
                security = new Security();
                try
                {
                    domain   = this.username.Split(char.Parse(@"\"))[0];
                    userName = this.username.Split(char.Parse(@"\"))[1];
                }
                catch (Exception /*ex*/)
                {
                    throw new ApplicationException(@"Username is formatted incorrectly. Please use computername\username");
                }
                security.Impersonate(userName, domain, this.password);
            }
        }