Ejemplo n.º 1
0
        public static DbConnection GetConnection(out string error, MsConnectionParams connectionParams)
        {
            error = "";

            try
            {
                switch (connectionParams.DatabaseType)
                {
                    case MsDatabaseType.Firebird:
            #if !NET20
                        return new FbConnection(connectionParams.GetConnectionString());
            #else
                        error = Messages.databaseNotSupported;
                        return null;
            #endif
                    case MsDatabaseType.SqlServer:
                        return new SqlConnection(connectionParams.GetConnectionString());
                    case MsDatabaseType.None:
                        error = Messages.databaseTypeNotSelected;
                        return null;
                    case MsDatabaseType.Other:
                        error = Messages.databaseNotSupported;
                        return null;
                    default:
                        error = Messages.databaseNotSupported;
                        return null;
                }
            }
            catch (Exception err)
            {
                error = err.Message;
                return null;
            }
        }
Ejemplo n.º 2
0
 private void BtnConnectionForm_Click(object sender, RoutedEventArgs e)
 {
     var connectionParams = new MsConnectionParams();
     var connectionForm = new msConnectionFormWpf();
     if (connectionForm.showDialog("wpf test", ref connectionParams))
     {
         MessageBox.Show(connectionParams.ToString());
         MessageBox.Show(connectionParams.GetConnectionString());
     }
 }
Ejemplo n.º 3
0
 private void btnTestMsConnectionForms_Click(object sender, EventArgs e)
 {
     var connectionForm = new msConnectionForm();
     var connectionParams = new MsConnectionParams();
     if (connectionForm.showDialog("msUtilities Test App", ref connectionParams))
     {
         MessageBox.Show(connectionParams.ToString());
         MessageBox.Show(connectionParams.GetConnectionString());
     }
 }
Ejemplo n.º 4
0
 private void btnTestMsConnectionFormsSqlServer_Click(object sender, EventArgs e)
 {
     var connectionForm = new msConnectionForm();
     var connectionParams = new MsConnectionParams();
     connectionParams.DatabaseType = MsDatabaseType.SqlServer;
     connectionParams.Database = "database";
     if (connectionForm.showDialog("msUtilities Test App", ref connectionParams))
     {
         MessageBox.Show(connectionParams.ToString());
         MessageBox.Show(connectionParams.GetConnectionString());
     }
 }
        public void TestConnectionParamsFromXmlOld()
        {
            var xml = new XmlDocument();
            var xmlElement = xml.CreateElement("connection");
            xmlElement.SetAttribute("databaseType", "dtFirebird");
            xmlElement.SetAttribute("databaseTypeCustom", "");
            xmlElement.SetAttribute("host", Host);
            xmlElement.SetAttribute("DatabaseName", DatabaseName);
            xmlElement.SetAttribute("username", User);
            xmlElement.SetAttribute("password", MsStringCipher.Encrypt(Password, EncryptionKey));

            var conn = new MsConnectionParams(xmlElement, EncryptionKey);

            Assert.AreEqual(MsDatabaseType.Firebird, conn.DatabaseType);
            Assert.AreEqual(Password, conn.Password);
        }
        public void TestConnectionParamsToXml()
        {
            var conn = new MsConnectionParams(
              MsDatabaseType.Firebird,
              User,
              Password,
              Host,
              DatabaseName
              );

            var xml = new XmlDocument();
            var xmlElement = xml.CreateElement("connection");
            conn.ToXml(xmlElement, EncryptionKey);

            Assert.AreEqual("user", xmlElement.GetAttribute("username"));
            Assert.AreNotEqual("password", xmlElement.GetAttribute("password"));
            Assert.AreEqual("password", MsStringCipher.Decrypt(xmlElement.GetAttribute("password"), EncryptionKey));
        }
Ejemplo n.º 7
0
 public static DbCommand GetCommand(MsConnectionParams connectionParams, DbConnection dbConn, string commandText)
 {
     switch (connectionParams.DatabaseType)
     {
         case MsDatabaseType.Firebird:
     #if !NET20
             return new FbCommand(commandText, (FbConnection)dbConn);
     #else
             return null;
     #endif
         case MsDatabaseType.SqlServer:
             return new SqlCommand(commandText, (SqlConnection)dbConn);
         case MsDatabaseType.None:
             return null;
         case MsDatabaseType.Other:
             return null;
         default:
             return null;
     }
 }
Ejemplo n.º 8
0
        public static string DatabaseConnectionTest(MsConnectionParams connectionParams)
        {
            string error;

            var dbConn = GetConnection(out error, connectionParams);
            if (dbConn == null)
            {
                return string.Format(Messages.databaseNotConfigured, error);
            }
            else
            {
                try
                {
                    dbConn.Open();
                    dbConn.Close();
                    return string.Format(Messages.databaseConnectionTestResult, connectionParams.Host, connectionParams.Database);
                }
                catch (Exception err)
                {
                    return string.Format(Messages.databaseConnectionError, connectionParams.Host, connectionParams.Database, err.Message);
                }
            }
        }
        public void TestConnectionStringGenerationFirebirdEmpty()
        {
            var conn = new MsConnectionParams
            {
                DatabaseType = MsDatabaseType.Firebird,
                Username = User,
                Password = Password,
                Host = Host,
                Database = DatabaseName
            };

            var test = $"User={User};Password={Password};Database={DatabaseName};DataSource={Host};";
            var result = conn.GetConnectionString();

            Assert.AreEqual(test, result);
        }
        public void TestConnectionStringGenerationSqlServer()
        {
            var conn = new MsConnectionParams(
              MsDatabaseType.SqlServer,
              User,
              Password,
              Host,
              DatabaseName
              );

            var test = $"User Id={User};Password={Password};Database={DatabaseName};Server={Host};";
            var result = conn.GetConnectionString();

            Assert.AreEqual(test, result);
        }
        public void TestConnectionStringGenerationOther()
        {
            var conn = new MsConnectionParams(
              MsDatabaseType.Other,
              User,
              Password,
              Host,
              DatabaseName
              );

            const string test = "";
            var result = conn.GetConnectionString();

            Assert.AreEqual(test, result);
        }
Ejemplo n.º 12
0
 public static DbParameter GetParameter(MsConnectionParams connectionParams, string paramName, object paramValue)
 {
     switch (connectionParams.DatabaseType)
     {
         case MsDatabaseType.Firebird:
     #if !NET20
             return new FbParameter(paramName, paramValue);
     #else
             return null;
     #endif
         case MsDatabaseType.SqlServer:
             return new SqlParameter(paramName, paramValue);
         case MsDatabaseType.None:
             return null;
         case MsDatabaseType.Other:
             return null;
         default:
             return null;
     }
 }