In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use ADO in Windows to remotely access PostgreSQL. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Windows uses odbc to access PostgreSQL
1. download
Postgresql corresponding odbc driver installation file (32-bit or 64-bit), msi file, URL:
Http://www.postgresql.org/ftp/odbc/versions/msi/
Next installation, installed in C:\ Program Files (x86)\ psqlODBC or C:\ Program Files\ psqlODBC
two。 Configuration
Open Control Panel-> Administrative tools-> data sources (ODBC), as follows:
According to the selection made by the system, 32-bit and 64-bit ODBC data sources actually correspond to the same executable file C:\ Windows\ System32\ odbcad32.exe;, as follows:
The Test' button can be used to test the success of the connection, which means it can be used in VS.
3.32-bit and 64-bit problems
Although the same odbcad32.exe file is called above, the configuration results are different.
The corresponding relationship is as follows:
ODBC data source (32-bit)-> can only add and edit 32-bit ODBC drivers (PostgreSQL is the same)-> Drive under registry "HKEY_CURRENT_USER\ Software\ ODBC\ ODBC.INI\ PostgreSQL35W" corresponds to 32-bit psqlodbc35w.dll files-> can only be applied to win32 programs on VS
64-bit mapping relationship is the same, at the same time modify the registry or one of the data sources, the exception will also be changed, the two correspond
At the same time, note that the Data Source used for the connection is PostgreSQL 35W, and this Data Source setting will be used in VS's C++ program.
4.VS program connection
At the end of the program code, this kind of method uses an ado connection, just changing the data source, namely Data Source, to the PostgreSQL35W corresponding to ODBC.
VS uses ADO to remotely access PostgreSQL
Insufficient 1.odbc
Using ODBC remote connection PostgreSQL to configure the database, such as IP,Port,User ID,PWD, should be configured on the windows system and cannot be modified in the program, which is not conducive to the migration of the program.
two。 Concrete realization
Implementation such as code
Problems that have occurred:
1. To use ado to manipulate the database, introduce the following code
# import "C:\ Program Files\ Common Files\ System\ ado\ msado15.dll" no_namespace rename ("EOF", "adoEOF")
The compiler prompts:
IntelliSense: unable to open source file... / Debug/msado15.tlh
The solution is very simple.
Just click regenerate on the build menu.
The reason is:
When the compiler encounters a # import statement, it generates a wrapper class for the interface in the reference component type library, and the # import statement actually executes the API culvert LoadTypeLib (). The # import statement generates two files in the project executable output directory, namely * .tlh (type library header file) and * .tli (type library implementation file). They generate smart pointers for each interface and declare various interface methods, enumerated types, CLSID, and so on, creating a series of wrapper methods.
The file has not been generated before it has been compiled by the compiler. As a result, an error message appears.
two。 Code problem
If you add * to the following program, the following problems (sometimes and sometimes not) will occur after closing the console or terminating the program, as follows:
Close (): when an object is closed, it is not deleted from memory, and the resource department is released. It is possible to change its settings and open it later, which can be used when using the open function.
Release (): release the resources occupied by the object, provided that the resources pointed to by m_pConnection and m_pRecordset are no longer used (as if closing the program or the console will destroy it again)
There is still a problem with the following explanation: (hope Daniel who knows it will give you some advice)
It is understood that after the close () call, the m_pRecordset pointer no longer points to the result set, so you can no longer release ().
After calling release (), the pointer no longer exists. If you still want to release the pointer when you close the program or the console, an error will be reported.
Code: (after installing the above configuration, you can run a successful test, win32)
# include using namespace std;#import "C:\ Program Files\ Common Files\ System\ ado\ msado15.dll" no_namespace rename ("EOF", "adoEOF") int main () {:: CoInitialize (NULL); _ ConnectionPtr mconnectionism HRESULT hr;// using ADO connection data configuration / / _ bstr_t strConnect = "Provider=PostgreSQL OLE DB Provider;Data Source=211.87.224.138;Location=shape;"; / / data configuration using ODBC connection _ bstr_t strConnect = "Data Source=PostgreSQL35W" Try {hr = m_pConnection.CreateInstance ("ADODB.Connection"); / / create Connection object if (SUCCEEDED (hr)) {hr = xhuyong connection-> Open (strConnect, "xhuyong", "123456", adModeUnknown); if (mroompConnection-> State) cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.