日本語マニュアル
5.8.1 GeoJSON
5.8.2 Json.NET
5.8.5 NodaTime
5.8.6 RawPostGIS
EDB Postgres™ Advanced Server
.NET Connector Guide
In the following descriptions a term refers to any word or group of words that are language keywords, user-supplied values, literals, etc. A term’s exact meaning depends upon the context in which it is used.
•
Italic font introduces a new term, typically, in the sentence that defines it for the first time.
•
Fixed-width (mono-spaced) font is used for terms that must be given literally such as SQL commands, specific table and column names used in the examples, programming language keywords, etc. For example, SELECT * FROM emp;
•
Italic fixed-width font is used for terms for which the user must substitute values in actual usage. For example, DELETE FROM table_name;
•
Square brackets [ ] denote that one or none of the enclosed term(s) may be substituted. For example, [ a | b ], means choose one of “a” or “b” or neither of the two.
•
Braces {} denote that exactly one of the enclosed alternatives must be specified. For example, { a | b }, means exactly one of “a” or “b” must be specified.
•
Ellipses ... denote that the proceeding term may be repeated. For example, [ a | b ] ... means that you may have the sequence, “b a a b a”.
•
•
The EDBConnection class represents a connection to Advanced Server. An EDBConnection object contains a ConnectionString that instructs the .NET client how to connect to an Advanced Server database.
An EDBCommand object contains an SQL command that the client will execute against Advanced Server. Before you can execute an EDBCommand object, you must link it to an EDBConnection object.
An EDBDataReader object provides a way to read an Advanced Server result set. You can use an EDBDataReader object to step through one row at a time, forward-only.
An EDBDataAdapter object links a result set to the Advanced Server database. You can modify values and use the EDBDataAdapter class to update the data stored in an Advanced Server database.
When the Language Selection popup opens, select an installation language and click OK to continue to the Setup window (shown in Figure 2.1).
Click Next to continue.
Use the Installation Directory dialog (see Figure 2.2) to specify the directory in which the connector will be installed, and click Next to continue.
Click Next on the Ready to Install dialog (see Figure 2.3) to start the installation; popup dialogs confirm the progress of the installation wizard.
When the wizard informs you that it has completed the setup, click the Finish button to exit the dialog (see Figure 2.4).
C:\Users\susan\AppData\Local\Temp\vmware-susan\VMwareDnD\7412d23f\Screen Shot 2016-07-11 at 4.50.20 PM.png
When StackBuilder Plus opens, follow the onscreen instructions. Select the EnterpriseDB .Net Connector option from the Database Drivers node of the tree control (see Figure 2.6).
•
Referencing the Library Files. General configuration information applicable to all components.
•
.NET Framework 4.0. Instructions for configuring for usage with .NET Framework 4.0.
•
.NET Framework 4.5. Instructions for configuring for usage with .NET Framework 4.5.
•
.NET Framework 4.5.1. Instructions for configuring for usage with .NET Framework 4.5.1.
•
.NET Standard 2.0. Instructions for configuring for usage with .NET Standard 2.0.
•
Entity Framework 5/6. Instructions for configuring for usage with Entity Framework.
•
EnterpriseDB VSIX. Instructions for configuring for usage with EnterpriseDB VSIX.
1.
Select the project in the Solution Explorer.
2.
Select Add Reference from the Project menu.
3.
When the Add Reference dialog box opens, browse to select the appropriate library files.
See Section 4.2.1 for information on referencing library files.
Note: You must also add the following dependencies to your project:
See Section 4.2.1 for information on referencing library files.
Note: You must also add the following dependencies to your project:
See Section 4.2.1 for information on referencing library files.
Note: You must also add the following dependencies to your project:
Note: If your target framework is .Net Core 2.0, then include the following file in your project:
See Section 4.2.1 for information about library files.
Note: Entity Framework can be used with EnterpriseDB.EDBClient.dll available in the net45 and net451 subdirectories.
See Section 4.2.1 for information about referencing library files.
Add the <DbProviderFactories> entries for the ADO.NET driver of EDB Postgres in the app.config file. The following are the entries:
In the project’s app.config file add the following entry for provider services under the EntityFramework/providers tag.
Note: The same entries for <providers> and <DbProviderFactories> are valid for the web.config file as well as for app.config.
EDB Data Designer Extensibility Provider (EnterpriseDB VSIX) is a component, which integrates Advanced Server database access into Visual Studio, thus providing Visual Studio integrated features.
EnterpriseDB.vsix
SSDLToPgSQL.tt
Step 1: Install EnterpriseDB VSIX to the desired version of Visual Studio with the EnterpriseDB.vsix installer at the following location:
It is no longer necessary or recommended to have EnterpriseDB.EDBClient in your global assembly cache (GAC).
Step 2: Relaunch Visual Studio and verify from Tools > Extensions and Updates… menu that the EnterpriseDB extension is installed.
Step 3: Add the System.ValueTuple.dll assembly in the global assembly cache (GAC) with the gacutil utility using the Visual Studio Developers Command line from the following location.
Step 4: From Server Explorer, right-click on Data Connections, click Add Connection, and verify the Enterprisedb Postgres Database data source is available.
Step 1: Add the EntityFramework5.EnterpriseDB.EDBClient.dll assembly in the global assembly cache (GAC) with the gacutil utility using the Visual Studio Developers Command line.
Step 2: Add the <DbProviderFactories> entries for the ADO.NET driver of EDB Postgres in the machine.config file. The following are the entries:
Note: For the attribute-value pairs, the double-quoted strings should not contain excess white space characters, but be configured on a single line. The examples shown in this section may be split on multiple lines for clarity, but should actually be configured within a single line such as the following:
For 64-bit Windows, the machine.config file is in the following location:
For 32-bit Windows, the machine.config file is in the following location:
Step 3: Place the DDL generation template SSDLToPgSQL.tt in the Visual Studio EntityFramework Tools\DBGen\ folder as in the following example:
Note: Select this template SSDLToPgSQL.tt in your EDMX file properties.
Step 4: Add files EnterpriseDB.EDBClient.dll and EntityFramework6.EnterpriseDB.EDBClient.dll in project references. See Section 4.2.1 for information about referencing library files.
Step 5: In the project’s app.config file add the following entry for provider services under the EntityFramework/providers tag.
Please create and save the following web.config file in the same directory as the sample code. The examples make use of the DB_CONN_STRING key from this configuration file to return a connection string from the Advanced Server host.
An Advanced Server connection string for an ASP.NET web application is stored in the web.config file. If you are writing an application that does not use ASP.NET, provide the connection information in an application configuration file (such as app.config).
An EDBConnection object is responsible for handling the communication between an instance of Advanced Server and a .NET application. Before you can access data stored in an Advanced Server database, you must create and open an EDBConnection.
1.
Import the namespace EnterpriseDB.EDBClient.
2.
Create an instance of EDBConnection.
3.
Initialize the EDBConnection object by passing a connection string as a parameter to the constructor for the EDBConnection class.
4.
Call the Open method of the EDBConnection object to open the connection.
CommandTimeout specifies the length of time (in seconds) to wait for a command to finish execution before throwing an exception. The default value is 20.
Use ConnectionLifeTime to specify the length of time (in seconds) to wait before closing unused connections in the pool. The default value is 15.
Use the Database parameter to specify the name of the database to which the application should connect. If a database name is not specified, the database name will default to the name of the connecting user.
The Encoding parameter is obsolete; the parameter always returns the string unicode, and silently ignores attempts to set it.
By default, Integrated Security is set to false, and Windows Integrated Security is disabled. Specify a value of true to use Windows Integrated Security.
MaxPoolSize instructs EDBConnection to dispose of pooled connections when the pool exceeds the specified number of connections. The default value is 20.
MinPoolSize instructs EDBConnection to pre-allocate the specified number of connections with the server. The default value is 1.
By default, Pooling is set to true to enable connection pooling. Specify a value of false to disable connection pooling.
The Port parameter specifies the port to which the application should connect.
Use the SearchPath parameter to change the search path to named and public schemas.
By default, SSL is set to false; specify a value of true to attempt a secure connection.
Use sslmode to specify an SSL connection control preference. sslmode can be:
prefer - Use SSL if possible.
require - Throw an exception if an SSL connection cannot be established.
allow - Connect without SSL. This parameter is not supported.
disable - Do not attempt an SSL connection. This is the default behavior.
Use the SyncNotification parameter to specify that EDBDataprovider should use synchronous notifications. The default value is false.
Timeout specifies the length of time (in seconds) to wait for an open connection. The default value is 15.
User Id
The User Id parameter specifies the user name that should be used for the connection.
The following example demonstrates how to open a connection to an instance of Advanced Server and then close the connection. The connection is established using the credentials specified in the DB_CONN_STRING configuration parameter (see the beginning of Chapter 5 for an introduction to connection information and Section 5.1.1 for connection parameters).
Screen Shot 2014-06-26 at 8
Before writing the code for the console application, create an app.config file that stores the connection string to the database. Using a configuration file makes it convenient to update the connection string if the information changes.
Save the file as EDBConnection-Sample.cs and compile it with the following command:
Compiling the sample should generate a Console.exe file; you can execute the sample code by entering Console.exe. When executed, the console should verify that the:
This command should generate a WinForm.exe file within the same folder that the executable was compiled under. Invoking the executable will display:
dialog
You can use a SELECT statement to retrieve records from the database via a SELECT command. To execute a SELECT statement you must:
•
Create an EDBCommand object that represents the SELECT statement.
•
Execute the command with the ExecuteReader() method of the EDBCommand object returning a EDBDataReader
•
Loop through the EDBDataReader displaying the results or binding the EDBDataReader to some control.
An EDBDataReader object represents a forward-only and read-only stream of database records, presented one record at a time. To view a subsequent record in the stream, you must call the Read() method of the EDBDataReader object.
1.
2.
Initializes an EDBCommand object with a SELECT statement.
4.
Executes the EDBCommand by calling the ExecuteReader method of the EDBCommand object.
5.
Loops through the contents of the EDBDataReader object to display the records returned by the query within a WHILE loop.
The Read() method advances to the next record (if a record exists) and returns true if a record exists, or false to indicate that the EDBDataReader has reached the end of the result set.
http://localhost/selectEmployees.aspx.
To retrieve a single result from a query, use the ExecuteScalar() method of the EDBCommand object. The ExecuteScalar() method returns the first value of the first column of the first row of the DataSet generated by the specified query.
Please note that the sample includes an explicit conversion of the value returned by the ExecuteScalar() method. The ExecuteScalar() method returns an object; to view the object, you must convert it into an integer value by using the Convert.ToInt32 method.
A parameterized query is a query with one or more parameter markers embedded in the SQL statement. Before executing a parameterized query, you must supply a value for each marker found in the text of the SQL statement.
As demonstrated in the following example, you must declare the data type of each parameter specified in the parameterized query by creating an EDBParameter object and adding that object to the command's parameter collection. Then, you must specify a value for each parameter by calling the parameter's Value() function.
The example demonstrates use of a parameterized query with an UPDATE statement that increases an employee salary:
You can use the ExecuteNonQuery() method of EDBCommand to add records to a database stored on an Advanced Server host with an Insert command.
In the example that follows, the insert command is stored in the variable cmd. The values prefixed with a colon (:) are placeholders for EDBParameters that are instantiated, assigned values, and then added to the insert command's parameter collection in the statements that follow. The insert command is executed by the ExecuteNonQuery() method of the cmdInsert object.
You can use the ExecuteNonQuery() method of EDBCommand to delete records from a database stored on an Advanced Server host with a Delete statement.
In the example that follows, the delete command is stored in the variable strDeleteQuery. The code passes the employee number to the Delete command (specified by :EmpNo). The command is then executed using the ExecuteNonQuery() method. The following example deletes the employee inserted in the previous example:
2.
Import the EnterpriseDB.EDBClient namespace.
4.
Change the EDBCommand.CommandType to CommandType.StoredProcedure.
5.
Prepare() the command.
Our sample procedure prints the name of department 10; the procedure takes no parameters, and returns no parameters. To create the sample procedure, invoke EDB-PSQL and connect to the Advanced Server host database. Enter the following SPL code at the command line:
The CommandType property of the EDBCommand object is used to indicate the type of command being executed. The CommandType property is set to one of three possible CommandType enumeration values:
•
Use the default Text value when passing a SQL string for execution.
•
Use the StoredProcedure value, passing the name of a stored procedure for execution.
•
Use the TableDirect value when passing a table name. This value passes back all records in the specified table.
The CommandText property must contain a SQL string, stored procedure name, or table name depending on the value of the CommandType property.
The following example demonstrates calling a stored procedure that includes IN parameters. To create the sample procedure, invoke EDB-PSQL and connect to the Advanced Server host database. Enter the following SPL code at the command line:
Calling a stored procedure that contains parameters is very similar to executing a stored procedure without parameters. The major difference is that when calling a parameterized stored procedure you must use the EDBParameter collection of the EDBCommand object. When the EDBParameter is added to the EDBCommand collection, properties such as ParameterName, DbType, Direction, Size, and Value are set.
In the example, the body of the Page_Load method declares and instantiates an EDBConnection object. The sample then creates an EDBCommand object with the properties needed to execute the stored procedure.
The example then uses the Add method of the EDBCommand Parameter collection to add six input parameters.
The Prepare() method prepares the statement before calling the ExecuteNonQuery() method.
The ExecuteNonQuery method of the EDBCommand object executes the stored procedure. After the stored procedure has executed, a test record is inserted into the emp table and the values inserted are displayed on the webpage.
The previous example demonstrated how to pass IN parameters to a stored procedure; the following examples demonstrate how to pass IN values and return OUT values from a stored procedure.
When retrieving values from OUT parameters you must explicitly specify the direction of out parameters as Output. You can retrieve the values from Output parameters in two ways:
•
Call the ExecuteReader method of the EDBCommand and explicitly loop through the returned EDBDataReader, searching for the values of OUT parameters.
•
Call the ExecuteNonQuery method of EDBCommand and explicitly get the value of a declared Output parameter by calling that EDBParameter value property.
In each method, you must declare each parameter, indicating the direction of the parameter (ParameterDirection.Input, ParameterDirection.Output or ParameterDirection.InputOutput). Before invoking the procedure, you must provide a value for each IN and INOUT parameter. After the procedure returns, you may retrieve the OUT and INOUT parameter values from the command.Parameters[] array.
The following code listing demonstrates using the ExecuteReader method to retrieve a result set:
The following code listing demonstrates using the ExecuteNonQuery method to retrieve a result set:
A ref cursor is a cursor variable that contains a pointer to a query result set. The result set is determined by the execution of the OPEN FOR statement using the cursor variable. A cursor variable is not tied to a particular query like a static cursor. The same cursor variable may be opened a number of times with the OPEN FOR statement containing different queries and each time, a new result set will be created for that query and made available via the cursor variable. There are two ways to declare a cursor variable:
•
Use the SYS_REFCURSOR built-in data type to declare a weakly-typed ref cursor.
SYS_REFCURSOR is a ref cursor type that allows any result set to be associated with it. This is known as a weakly-typed ref cursor. The following example is a declaration of a weakly-typed ref cursor:
TYPE cursor_type_name IS REF CURSOR RETURN emp%ROWTYPE;
The following sample code creates a stored procedure called refcur_inout_callee. To create the sample procedure, invoke EDB-PSQL and connect to the Advanced Server host database. Enter the following SPL code at the command line:
Please note that you must bind the EDBDbType.RefCursor type in EDBParameter() if you are using a ref cursor parameter.

•
5.8.1 GeoJSON
5.8.2 Json.NET
C:\Program Files\edb\dotnet\ plugins\NetTopologySuite\net45
5.8.5 NodaTime
5.8.6 RawPostGIS
•
When using the API, replace references to Npgsql with EnterpriseDB.EDBClient.
•
When referring to classes, replace Npgsql with EDB. For example, use the EDBBinaryExporter class instead of the NpgsqlBinaryExporter class.