Exemplo n.º 1
0
 public SQLConnectionHelper()
 {
     this.serverNames = new ArrayList();
     this.defaultServerName = "";
     this.sqlConnectionStr = new SQLConnectionString();
     this.isConnected = false;
     this.sqlConnection = null;
     this.databases = new ArrayList();
     this.tables = new ArrayList();
 }
Exemplo n.º 2
0
 public object Clone()
 {
     SQLConnectionString scs = new SQLConnectionString();
     scs.auth = auth;
     scs.database = database;
     scs.password = password;
     scs.server = server;
     scs.user = user;
     return scs;
 }
Exemplo n.º 3
0
        private void lbScheduleEvents_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.lbScheduleEvents.SelectedIndex < 0)
                return;

            ScheduleEvent schedEvent = (ScheduleEvent)this.lbScheduleEvents.SelectedItem;
            SQLConnectionString sqlConnString = new SQLConnectionString();
            sqlConnString.ConnectionString = schedEvent.SQLConnectionString;
            if (this.cbServerNames.Items.Contains(sqlConnString.Server))
            {
                this.cbServerNames.Text = sqlConnString.Server;
            }
            else
            {
                DialogResult result = MessageBox.Show(
                    "Nie ma takiej bazy na liście.\n\nCzy chcesz usnąć to zdarzenie z listy?",
                    "Ostrzeżenie",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question
                    );

                if (result == DialogResult.Yes)
                {
                    object toDelete = lbScheduleEvents.SelectedItem;
                    lbScheduleEvents.Items.Remove(toDelete);
                    this.events.Remove(toDelete);
                    this.events.Save();
                }
            }
        }
Exemplo n.º 4
0
        private static void DisplayData(System.Data.DataTable table)
        {
            String srvName = "";

            foreach (System.Data.DataRow row in table.Rows)
            {
                if (srvName.Equals(""))
                {
                    srvName = row["ServerName"] + "\\" + row["InstanceName"];
                }
                else
                {
                    if (!row["InstanceName"].Equals("SQLEXPRESS"))
                    {
                        srvName = row["ServerName"] + "\\" + row["InstanceName"];
                    }

                }
                Console.WriteLine(row["ServerName"] + "\\" + row["InstanceName"]);

                SQLConnectionString sqlConnStr = new SQLConnectionString();

                sqlConnStr.Server = srvName;
                sqlConnStr.Authentication = true;
                /*
                if (!rbAuthWindows.Checked)
                {
                    sqlConnStr.UserID = txtUser.Text;
                    sqlConnStr.Password = txtPassword.Text;
                }
                */

                using (SqlConnection sqlConn = new SqlConnection(sqlConnStr.ConnectionString))
                {
                    try
                    {
                        sqlConn.Open();

                        DataTable tblDatabases = sqlConn.GetSchema("Databases");

                        foreach (DataRow rowDBs in tblDatabases.Rows)
                        {
                            Console.WriteLine(rowDBs["database_name"]);

                            if (rowDBs["database_name"].Equals("MagresNET"))
                            {
                                sqlConn.ChangeDatabase("MagresNET");
                                Console.WriteLine("Found and selected");

                                DataTable dt = sqlConn.GetSchema("Tables");
                                foreach (DataRow rowTables in dt.Rows)
                                {
                                    Console.WriteLine(rowTables["table_name"]);
                                }
                            }

                        }

                        sqlConn.Close();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("EX: " + ex.Message);
                        Console.WriteLine("EX: " + sqlConnStr.ConnectionString);
                    }
                }
            }
            /*
            foreach (System.Data.DataRow row in table.Rows)
            {
                foreach (System.Data.DataColumn col in table.Columns)
                {
                    Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
                }
                Console.WriteLine("============================");
            }
            */
        }