public override IDbConnection Open (out string errorMessage)
		{
			FbConnectionStringBuilder builder = null;
			try {	
				if (settings.UseConnectionString) {
					builder = new FbConnectionStringBuilder (settings.ConnectionString);
				} else {
					builder = new FbConnectionStringBuilder ();
					builder.Database = settings.Database;
					builder.UserID = settings.Username;
					builder.Password = settings.Password;
					builder.Port = settings.Port;
					builder.DataSource = settings.Server;
				}
				builder.Pooling = settings.EnablePooling;
				builder.MinPoolSize = settings.MinPoolSize;
				builder.MaxPoolSize = settings.MaxPoolSize;
				connection = new FbConnection (builder.ToString ());
				connection.Open ();
				
				errorMessage = String.Empty;
				isConnectionError = false;
				return connection;
			} catch {
				isConnectionError = true;
				errorMessage = String.Format ("Unable to connect. (CS={0})", builder == null ? "NULL" : builder.ToString ());
				return null;
Esempio n. 2
0
        public static void DropDatabase(Hashtable values)
        {
            int serverType = 0;

            if (!values.ContainsKey("User") ||
                !values.ContainsKey("Password") ||
                !values.ContainsKey("Database"))
            {
                throw new ArgumentException("CreateDatabase requires a user name, password and database path.");
            }

            if (!values.ContainsKey("DataSource"))
            {
                values.Add("DataSource", "localhost");
            }

            if (!values.ContainsKey("Port"))
            {
                values.Add("Port", 3050);
            }

            if (values.ContainsKey("ServerType"))
            {
                serverType = Convert.ToInt32(values["ServerType"], CultureInfo.InvariantCulture);
            }

            try
            {
                // Configure Attachment
                FbConnectionStringBuilder csb = new FbConnectionStringBuilder();

                csb.DataSource = values["DataSource"].ToString();
                csb.Port       = Convert.ToInt32(values["Port"], CultureInfo.InvariantCulture);
                csb.Database   = values["Database"].ToString();
                csb.UserID     = values["User"].ToString();
                csb.Password   = values["Password"].ToString();
                csb.ServerType = serverType;

                FbConnectionString options = new FbConnectionString(csb);

                // Drop	the	database
                FbConnectionInternal db = new FbConnectionInternal(options);
                db.DropDatabase();
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
Esempio n. 3
0
        /// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="ChangeDatabase(System.String)"]/*'/>
        public void ChangeDatabase(string db)
        {
            lock (this)
            {
                if (this.IsClosed)
                {
                    throw new InvalidOperationException("ChangeDatabase requires an open and available Connection.");
                }

                if (db == null || db.Trim().Length == 0)
                {
                    throw new InvalidOperationException("Database name is not valid.");
                }

                string cs = this.connectionString;

                try
                {
                    FbConnectionStringBuilder csb = new FbConnectionStringBuilder(this.connectionString);

                    // Close current connection
                    this.Close();

                    // Set up the new Database
                    csb.Database = db;

                    // Open	new	connection
                    this.Open();
                }
                catch (IscException ex)
                {
                    this.ConnectionString = cs;
                    throw new FbException(ex.Message, ex);
                }
            }
        }
		/// <include file='Doc/en_EN/FbConnection.xml' path='doc/class[@name="FbConnection"]/method[@name="ChangeDatabase(System.String)"]/*'/>
		public void ChangeDatabase(string db)
		{
			lock (this)
			{
				if (this.IsClosed)
				{
					throw new InvalidOperationException("ChangeDatabase requires an open and available Connection.");
				}

				if (db == null || db.Trim().Length == 0)
				{
					throw new InvalidOperationException("Database name is not valid.");
				}

				string cs = this.connectionString;

				try
				{
					FbConnectionStringBuilder csb = new FbConnectionStringBuilder(this.connectionString);

					// Close current connection
					this.Close();

					// Set up the new Database
					csb.Database = db;

					// Open	new	connection
					this.Open();
				}
				catch (IscException ex)
				{
					this.ConnectionString = cs;
					throw new FbException(ex.Message, ex);
				}
			}
		}
		public static void DropDatabase(Hashtable values)
		{
			int serverType = 0;

			if (!values.ContainsKey("User") ||
				!values.ContainsKey("Password") ||
				!values.ContainsKey("Database"))
			{
				throw new ArgumentException("CreateDatabase requires a user name, password and database path.");
			}

			if (!values.ContainsKey("DataSource"))
			{
				values.Add("DataSource", "localhost");
			}

			if (!values.ContainsKey("Port"))
			{
				values.Add("Port", 3050);
			}

			if (values.ContainsKey("ServerType"))
			{
				serverType = Convert.ToInt32(values["ServerType"], CultureInfo.InvariantCulture);
			}

			try
			{
				// Configure Attachment
				FbConnectionStringBuilder csb = new FbConnectionStringBuilder();

				csb.DataSource = values["DataSource"].ToString();
				csb.Port = Convert.ToInt32(values["Port"], CultureInfo.InvariantCulture);
				csb.Database = values["Database"].ToString();
				csb.UserID = values["User"].ToString();
				csb.Password = values["Password"].ToString();
				csb.ServerType = serverType;

				FbConnectionString options = new FbConnectionString(csb);

				// Drop	the	database
				FbConnectionInternal db = new FbConnectionInternal(options);
				db.DropDatabase();
			}
			catch (IscException ex)
			{
				throw new FbException(ex.Message, ex);
			}
		}
		public static void CreateDatabase(Hashtable values)
		{
			bool overwrite = false;
			int index = 0;
			byte dialect = 3;
			int serverType = 0;

			if (!values.ContainsKey("User") ||
				!values.ContainsKey("Password") ||
				!values.ContainsKey("Database"))
			{
				throw new ArgumentException("CreateDatabase requires a user name, password and database path.");
			}

			if (values.ContainsKey("ServerType"))
			{
				serverType = Convert.ToInt32(values["ServerType"], CultureInfo.InvariantCulture);
			}

			if (!values.ContainsKey("DataSource"))
			{
				values.Add("DataSource", "localhost");
			}

			if (!values.ContainsKey("Port"))
			{
				values.Add("Port", 3050);
			}

			if (values.ContainsKey("Dialect"))
			{
				dialect = Convert.ToByte(values["Dialect"], CultureInfo.InvariantCulture);
			}

			if (dialect < 1 || dialect > 3)
			{
				throw new ArgumentException("Incorrect database dialect it should be 1, 2, or 3.");
			}

			if (values.ContainsKey("Overwrite"))
			{
				overwrite = (bool)values["Overwrite"];
			}

			try
			{
				// Configure Attachment
				FbConnectionStringBuilder csb = new FbConnectionStringBuilder();

				csb.DataSource	= values["DataSource"].ToString();
				csb.UserID		= values["User"].ToString();
				csb.Password	= values["Password"].ToString();
				csb.Database	= values["Database"].ToString();
				csb.Port		= Convert.ToInt32(values["Port"], CultureInfo.InvariantCulture);
				csb.ServerType	= serverType;

				FbConnectionString options = new FbConnectionString(csb);

				// DPB configuration
				DatabaseParameterBuffer dpb = new DatabaseParameterBuffer();

				// Dpb version
				dpb.Append(IscCodes.isc_dpb_version1);

				// Dummy packet	interval
				dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });

				// User	name
				dpb.Append(IscCodes.isc_dpb_user_name, values["User"].ToString());

				// User	password
				dpb.Append(IscCodes.isc_dpb_password, values["Password"].ToString());

				// Database	dialect
				dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { dialect, 0, 0, 0 });

				// Database overwrite
				dpb.Append(IscCodes.isc_dpb_overwrite, (short)(overwrite ? 1 : 0));

				// Character set
				if (values.ContainsKey("Charset"))
				{
					index = Charset.SupportedCharsets.IndexOf(values["Charset"].ToString());

					if (index == -1)
					{
						throw new ArgumentException("Character set is not valid.");
					}
					else
					{
						dpb.Append(
							IscCodes.isc_dpb_set_db_charset,
							Charset.SupportedCharsets[index].Name);
					}
				}

				// Page	Size
				if (values.ContainsKey("PageSize"))
				{
					dpb.Append(IscCodes.isc_dpb_page_size, Convert.ToInt32(values["PageSize"], CultureInfo.InvariantCulture));
				}

				// Forced writes
				if (values.ContainsKey("ForcedWrite"))
				{
					dpb.Append(IscCodes.isc_dpb_force_write,
						(short)((bool)values["ForcedWrite"] ? 1 : 0));
				}

				if (!overwrite)
				{
					try
					{
						// Check if	the	database exists
						FbConnectionInternal check = new FbConnectionInternal(options);

						check.Connect();
						check.Disconnect();

						IscException ex = new IscException(IscCodes.isc_db_or_file_exists);

						throw new FbException(ex.Message, ex);
					}
					catch (Exception)
					{
						throw;
					}
				}

				// Create the new database
				FbConnectionInternal c = new FbConnectionInternal(options);
				c.CreateDatabase(dpb);
			}
			catch (IscException ex)
			{
				throw new FbException(ex.Message, ex);
			}
		}
Esempio n. 7
0
        private void OpenDbConnection(string db, string uid, string pwd)
        {
            try
              {
            FbConnectionStringBuilder cs = new FbConnectionStringBuilder();

            cs.DataSource = "localhost";
            cs.Database = database;
            cs.UserID = userID;
            cs.Password = password;
            cs.Dialect = 3;
            dbSource = cs.ToString();

            dbConnection = new FbConnection (dbSource);
            dbConnection.Open ();
            dbCommand = new FbCommand (null, dbConnection);
            dbDataAdapter = new FbDataAdapter (dbCommand);
              }
              catch
              {
            dbConnection = null;
            IO.Error ("Unable to open database connection:\n{0}", dbSource);
              }
        }
		public FbConnectionString(FbConnectionStringBuilder csb)
			: this(csb.ToString())
		{
		}
Esempio n. 9
0
 public FbConnectionString(FbConnectionStringBuilder csb)
     : this(csb.ToString())
 {
 }
Esempio n. 10
0
        public static void CreateDatabase(Hashtable values)
        {
            bool overwrite  = false;
            int  index      = 0;
            byte dialect    = 3;
            int  serverType = 0;

            if (!values.ContainsKey("User") ||
                !values.ContainsKey("Password") ||
                !values.ContainsKey("Database"))
            {
                throw new ArgumentException("CreateDatabase requires a user name, password and database path.");
            }

            if (values.ContainsKey("ServerType"))
            {
                serverType = Convert.ToInt32(values["ServerType"], CultureInfo.InvariantCulture);
            }

            if (!values.ContainsKey("DataSource"))
            {
                values.Add("DataSource", "localhost");
            }

            if (!values.ContainsKey("Port"))
            {
                values.Add("Port", 3050);
            }

            if (values.ContainsKey("Dialect"))
            {
                dialect = Convert.ToByte(values["Dialect"], CultureInfo.InvariantCulture);
            }

            if (dialect < 1 || dialect > 3)
            {
                throw new ArgumentException("Incorrect database dialect it should be 1, 2, or 3.");
            }

            if (values.ContainsKey("Overwrite"))
            {
                overwrite = (bool)values["Overwrite"];
            }

            try
            {
                // Configure Attachment
                FbConnectionStringBuilder csb = new FbConnectionStringBuilder();

                csb.DataSource = values["DataSource"].ToString();
                csb.UserID     = values["User"].ToString();
                csb.Password   = values["Password"].ToString();
                csb.Database   = values["Database"].ToString();
                csb.Port       = Convert.ToInt32(values["Port"], CultureInfo.InvariantCulture);
                csb.ServerType = serverType;

                FbConnectionString options = new FbConnectionString(csb);

                // DPB configuration
                DatabaseParameterBuffer dpb = new DatabaseParameterBuffer();

                // Dpb version
                dpb.Append(IscCodes.isc_dpb_version1);

                // Dummy packet	interval
                dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, new byte[] { 120, 10, 0, 0 });

                // User	name
                dpb.Append(IscCodes.isc_dpb_user_name, values["User"].ToString());

                // User	password
                dpb.Append(IscCodes.isc_dpb_password, values["Password"].ToString());

                // Database	dialect
                dpb.Append(IscCodes.isc_dpb_sql_dialect, new byte[] { dialect, 0, 0, 0 });

                // Database overwrite
                dpb.Append(IscCodes.isc_dpb_overwrite, (short)(overwrite ? 1 : 0));

                // Character set
                if (values.ContainsKey("Charset"))
                {
                    index = Charset.SupportedCharsets.IndexOf(values["Charset"].ToString());

                    if (index == -1)
                    {
                        throw new ArgumentException("Character set is not valid.");
                    }
                    else
                    {
                        dpb.Append(
                            IscCodes.isc_dpb_set_db_charset,
                            Charset.SupportedCharsets[index].Name);
                    }
                }

                // Page	Size
                if (values.ContainsKey("PageSize"))
                {
                    dpb.Append(IscCodes.isc_dpb_page_size, Convert.ToInt32(values["PageSize"], CultureInfo.InvariantCulture));
                }

                // Forced writes
                if (values.ContainsKey("ForcedWrite"))
                {
                    dpb.Append(IscCodes.isc_dpb_force_write,
                               (short)((bool)values["ForcedWrite"] ? 1 : 0));
                }

                if (!overwrite)
                {
                    try
                    {
                        // Check if	the	database exists
                        FbConnectionInternal check = new FbConnectionInternal(options);

                        check.Connect();
                        check.Disconnect();

                        IscException ex = new IscException(IscCodes.isc_db_or_file_exists);

                        throw new FbException(ex.Message, ex);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }

                // Create the new database
                FbConnectionInternal c = new FbConnectionInternal(options);
                c.CreateDatabase(dpb);
            }
            catch (IscException ex)
            {
                throw new FbException(ex.Message, ex);
            }
        }
        public void FbConnectionStringBuilderTest()
        {
            FbConnectionStringBuilder cs = new FbConnectionStringBuilder();

            cs.DataSource = ConfigurationSettings.AppSettings["DataSource"];
            cs.Database = ConfigurationSettings.AppSettings["Database"];
            cs.Port = Convert.ToInt32(ConfigurationSettings.AppSettings["Port"]);
            cs.UserID = ConfigurationSettings.AppSettings["User"];
            cs.Password = ConfigurationSettings.AppSettings["Password"];
            cs.ServerType = Convert.ToInt32(ConfigurationSettings.AppSettings["ServerType"]);
            cs.Charset = ConfigurationSettings.AppSettings["Charset"];
            cs.Pooling = Convert.ToBoolean(ConfigurationSettings.AppSettings["Pooling"]);

            using (FbConnection c = new FbConnection(cs.ToString()))
            {
                c.Open();
            }

        }
		/// <summary>
		/// Creates	an instance	of FbBatchExecution	engine.
		/// </summary>
		public FbBatchExecution()
		{
			this.sqlConnection	 = new FbConnection(); // do	not	specify	the	connection string
			this.connectionString = new FbConnectionStringBuilder();
		}
		public FbBatchExecution(FbConnection sqlConnection, FbScript isqlScript)
		{
			if (sqlConnection == null)
			{
				this.sqlConnection	 = new FbConnection(); // do	not	specify	the	connection string
				this.connectionString = new FbConnectionStringBuilder();
			}
			else
			{
				this.sqlConnection	 = sqlConnection;
				this.connectionString = new FbConnectionStringBuilder(sqlConnection.ConnectionString);
			}

            if (isqlScript != null)
            {
                foreach (string sql in isqlScript.Results)
                {
                    this.SqlStatements.Add(sql);
                }
            }
		}