示例#1
0
		public int Connect(string database, string user, string password, string hostName)
		{
			int		port		= 3050;
			string	dataSource	= hostName;
			string	dbPath		= database;

			try
			{
				string connectionString =
					String.Format(
					"{0}={1};{2}={3};{4}={5};{6}={7};{8}",
					"DataSource", hostName,
					"Database", database,
					"User", user,
					"Password", password,
					this.connectionOptions);

				FbConnectionString cs = new FbConnectionString();
				cs.ConnectionString = connectionString;

				Regex r = new Regex(@"(?<datasource>.*)/(?<port>[0-9]*):(?<database>.*)", RegexOptions.ExplicitCapture);

				Match m = r.Match(database);

				if (m != null)
				{
					if (m.Groups["datasource"].Success)
					{
						dataSource = m.Groups["datasource"].Value;
					}

					if (m.Groups["port"].Success)
					{
						port = Int32.Parse(m.Groups["port"].Value);
					}
				
					if (m.Groups["database"].Success)
					{
						dbPath = m.Groups["database"].Value;
					}
				}

				//  Create database instance
				this.db = ClientFactory.CreateDatabase(cs.ServerType);

				// Build DPB
				DatabaseParameterBuffer dpb = this.db.CreateDatabaseParameterBuffer();

				dpb.Append(IscCodes.isc_dpb_version1);
				dpb.Append(IscCodes.isc_dpb_dummy_packet_interval, 
					new byte[] {120, 10, 0, 0});
				dpb.Append(IscCodes.isc_dpb_sql_dialect, 
					new byte[] {Convert.ToByte(cs.Dialect), 0, 0, 0});
				dpb.Append(IscCodes.isc_dpb_lc_ctype, cs.Charset);
				if (cs.RoleName != null)
				{
					if (cs.RoleName.Length > 0)
					{
						dpb.Append(IscCodes.isc_dpb_sql_role_name, cs.RoleName);
					}
				}
				dpb.Append(IscCodes.isc_dpb_user_name, user);
				dpb.Append(IscCodes.isc_dpb_password, password);

				// Perform attach
				this.db.Attach(dpb, dataSource, port, dbPath);
			}
			catch (IscException e)
			{
				this.lastError = e;
			}

			return this.GetErrorCode();
		}
示例#2
0
        public int Connect(string database, string user, string password, string hostName)
        {
            int    port       = 3050;
            string dataSource = hostName;
            string dbPath     = database;

            try
            {
                string connectionString =
                    String.Format(
                        "{0}={1};{2}={3};{4}={5};{6}={7};{8}",
                        "DataSource", hostName,
                        "Database", database,
                        "User", user,
                        "Password", password,
                        this.connectionOptions);

                FbConnectionString cs = new FbConnectionString();
                cs.ConnectionString = connectionString;

                Regex r = new Regex(@"(?<datasource>.*)/(?<port>[0-9]*):(?<database>.*)", RegexOptions.ExplicitCapture);

                Match m = r.Match(database);

                if (m != null)
                {
                    if (m.Groups["datasource"].Success)
                    {
                        dataSource = m.Groups["datasource"].Value;
                    }

                    if (m.Groups["port"].Success)
                    {
                        port = Int32.Parse(m.Groups["port"].Value);
                    }

                    if (m.Groups["database"].Success)
                    {
                        dbPath = m.Groups["database"].Value;
                    }
                }

                //  Create database instance
                this.db = ClientFactory.CreateDatabase(cs.ServerType);

                // Build DPB
                DatabaseParameterBuffer dpb = this.db.CreateDatabaseParameterBuffer();

                dpb.Append(IscCodes.isc_dpb_version1);
                dpb.Append(IscCodes.isc_dpb_dummy_packet_interval,
                           new byte[] { 120, 10, 0, 0 });
                dpb.Append(IscCodes.isc_dpb_sql_dialect,
                           new byte[] { Convert.ToByte(cs.Dialect), 0, 0, 0 });
                dpb.Append(IscCodes.isc_dpb_lc_ctype, cs.Charset);
                if (cs.RoleName != null)
                {
                    if (cs.RoleName.Length > 0)
                    {
                        dpb.Append(IscCodes.isc_dpb_sql_role_name, cs.RoleName);
                    }
                }
                dpb.Append(IscCodes.isc_dpb_user_name, user);
                dpb.Append(IscCodes.isc_dpb_password, password);

                // Perform attach
                this.db.Attach(dpb, dataSource, port, dbPath);
            }
            catch (IscException e)
            {
                this.lastError = e;
            }

            return(this.GetErrorCode());
        }