Exemple #1
0
        private static PhpResource Connect(string server, string user, string password, bool newLink, bool persistent)
        {
            // persistent connections are treated as transient, a warning is issued:
            if (persistent)
            {
                PhpException.FunctionNotSupported(PhpError.Notice);
            }

            MsSqlLocalConfig  local  = MsSqlConfiguration.Local;
            MsSqlGlobalConfig global = MsSqlConfiguration.Global;

            StringBuilder opts = new StringBuilder();

            if (local.ConnectTimeout > 0)
            {
                opts.AppendFormat("Connect Timeout={0}", local.ConnectTimeout);
            }

            if (global.NTAuthentication)
            {
                if (opts.Length > 0)
                {
                    opts.Append(';');
                }
                user = password = null;
                opts.Append("Integrated Security=true");
            }

            string connection_string = PhpSqlDbConnection.BuildConnectionString(server, user, password, opts.ToString());

            bool success;
            PhpSqlDbConnection connection = (PhpSqlDbConnection)GetManager().OpenConnection(connection_string,
                                                                                            newLink, global.MaxConnections, out success);

            if (!success)
            {
                if (connection != null)
                {
                    UpdateConnectErrorInfo(connection);
                    connection = null;
                }
                return(null);
            }

            return(connection);
        }