Exemplo n.º 1
0
 public static DataSet GetDataSet(String sql, string connstr, int timeout, Server server)
 {
     if (!sql.StartsWith("use", true, CultureInfo.CurrentCulture))
     {
         string db = connstr.Substring(connstr.IndexOf("initial catalog="));
         db = db.Substring(db.IndexOf("=") + 1);
         sql = "USE " + db + Environment.NewLine + sql;
     }
     sql = "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED " + Environment.NewLine + sql;
     sql = GetSqlForServer(sql, server);
     var retval = new DataSet();
     using (var adapter = GetDataAdapter(sql, connstr, timeout))
     {
         var fill = adapter.Fill(retval);
     }
     foreach (DataTable t in retval.Tables)
     {
         var svrcol = "ServerName";
         if (t.Columns["ServerName"] != null)
             svrcol = "_ServerName_";
         t.Columns.Add(svrcol);
         t.Columns[svrcol].SetOrdinal(0);
         foreach (DataRow dr in t.Rows)
         {
             dr[svrcol] = server.servername;
         }
     }
     return retval;
 }
Exemplo n.º 2
0
 public static String GetServerConnectionString(Server server)
 {
     return server.usesspi
         ? String.Format(SSPICONN, server.svr, server.database)
         : String.Format(SQLLOGINCONN, server.svr, server.username, server.password, server.database);
 }
Exemplo n.º 3
0
 public int AddServer(Server server)
 {
     return listServers.Add(server);
 }
Exemplo n.º 4
0
        private static string GetSqlForServer(string origSql, Server server)
        {
            StringBuilder retVal = new StringBuilder();
            string[] lines = origSql.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            bool include = true;
            bool insideIf = false;
            foreach (var line in lines)
            {
                if (line.StartsWith("#if"))
                {
                    if (insideIf)
                        throw new SyntaxErrorException("Don't know how to handle nested #ifs yet.");
                    else
                    {
                        insideIf = true;
                        retVal.AppendLine(); //Append empty line to keep line numbers consistent across calls.

                        var criteria = line.Substring(3).Trim().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (criteria.Length < 1)
                            throw new SyntaxErrorException("Malformed #if statement. No criteria specified.");
                        include = false;
                        foreach (var c in criteria)
                        {
                            var ops = c.Split(new char[] { '=', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            if (ops.Length < 2)
                                throw new SyntaxErrorException("Malformed #if statement. Invalid criteria format.");
                            if (ops[0] == "type" && server.type == ops[1])
                                include = true;
                            else if (ops[0] == "name" && server.servername == ops[1])
                                include = true;
                            if (include) break;
                        }
                    }
                }
                else if (line.StartsWith("#else"))
                {
                    if(insideIf)
                    {
                        // If we were inside an if statement and we had not matched, then we are eligible for the else statement
                        if (!include) include = true;
                        retVal.AppendLine(); //Append empty line to keep line numbers consistent across calls.
                    }
                    else
                        throw new SyntaxErrorException("Unexpected #endif found.");
                }
                else if (line.StartsWith("#endif"))
                {
                    if (insideIf)
                    {
                        insideIf = false;
                        include = true;
                        retVal.AppendLine(); //Append empty line to keep line numbers consistent across calls.
                    }
                    else
                        throw new SyntaxErrorException("Unexpected #endif found.");
                }
                else if (include)
                    retVal.AppendLine(line);
                else
                    retVal.AppendLine(); //Append empty line to keep line numbers consistent across calls.
            }
            return retVal.ToString();
        }
Exemplo n.º 5
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (rdoFolder.Checked)
            {
                var svrList = new ServerList();
                svrList.Name = tb_Name.Text;

                if (IsEdit)
                {
                    tn.Text = tb_Name.Text;
                    tn.Tag = svrList;
                }
                else
                {
                    TreeNode node = new TreeNode();
                    node.Text = svrList.Name;
                    node.Tag = svrList;
                    if (tn.Tag.GetType() == typeof(Server))
                    {
                        tn.Parent.Nodes.Add(node);
                    }
                    else if (tn.Tag.GetType() == typeof(ServerList))
                    {
                        tn.Nodes.Add(node);
                        tn.Expand();
                    }
                }
            }
            else if (rdoServer.Checked)
            {
                var svr = new Server();
                svr.servername = tb_Name.Text;
                svr.database = tb_Database.Text;
                svr.svr = tb_Location.Text;
                svr.password = cb_UseSqlCredentials.Checked ? tb_Password.Text : null;
                svr.username = cb_UseSqlCredentials.Checked ? tb_Username.Text : null;
                svr.usesspi = !cb_UseSqlCredentials.Checked;

                if (IsEdit)
                {
                    if (tn.Tag.GetType() == typeof(Server))
                    {
                        tn.Text = svr.servername;
                        tn.Tag = svr;
                    }
                }
                else
                {
                    TreeNode node = new TreeNode();
                    node.Text = tb_Name.Text;
                    node.Tag = svr;
                    if (tn.Tag.GetType() == typeof(Server))
                    {
                        tn.Parent.Nodes.Add(node);
                    }
                    else if (tn.Tag.GetType() == typeof(ServerList))
                    {
                        tn.Nodes.Add(node);
                        tn.Expand();
                    }
                }
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }