2011-03-12 117 views
2

我正在使用SQLAPI ++從我的Visual C++應用程序連接到Oracle。 只有當我在Win32控制檯應用程序模式下執行操作時,我纔可以輕鬆地從VC++連接到數據庫。Visual C++ Windows窗體項目中的鏈接器錯誤

但是,當我嘗試在Windows窗體項目中做同樣的事情時,我得到以下鏈接器錯誤。 有人可以幫助我,因爲我需要在窗體中輸入的值插入數據庫。

我的代碼是:

#include <SQLAPI.h> 
#include "stdafx.h" 
#include "Form1.h" 
#include <stdio.h> 
using namespace sqlapi; 
[STAThreadAttribute] 
int main(array<System::String ^> ^args) 
{ 
    SAConnection con; 
    SACommand cmd;  
    try 
    { 
     con.Connect("", "scott", "tiger", SA_Oracle_Client); 
     cmd.setConnection(&con); 
     cmd.setCommandText(
      "Create table test_tbl(fid integer, fvarchar20 varchar(20), fblob blob)"); 
     cmd.Execute(); 
     cmd.setCommandText(
      "Insert into test_tbl(fid, fvarchar20) values (1, 'Some string (1)')"); 
     cmd.Execute(); 
     con.Commit(); 
    } 
    catch(SAException &x) 
    { 
     try 
     { 
      con.Rollback(); 
     } 
     catch(SAException &) 
     { 
     } 
    } 
    // Enabling Windows XP visual effects before any controls are created 
    Application::EnableVisualStyles(); 
    Application::SetCompatibleTextRenderingDefault(false); 
    Application::Run(gcnew Form1()); 
    return 0; 
} 

而且我得到的錯誤是

sqlapi.obj : error LNK2028: unresolved token (0A000010) "public: void __clrcall SAConnection::Rollback(void)" ([email protected]@@$$FQAMXXZ) referenced in function [email protected]@[email protected]@@@Z$0 
sqlapi.obj : error LNK2028: unresolved token (0A000016) "public: void __clrcall SAConnection::Commit(void)" ([email protected]@@$$FQAMXXZ) referenced in function "int __clrcall main(cli::array<class System::String^>^)" ([email protected]@[email protected]@@@Z) 

sqlapi.obj : error LNK2028: unresolved token (0A000018) "public: void __clrcall SACommand::setCommandText(class SAString const &,enum SACommandType_t)" ([email protected]@@$$FQAMXAB[email protected]@[email protected]@@Z) referenced in function "int __clrcall main(cli::array<class System::String^>^)" ([email protected]@[email protected]@@@Z) 
sqlapi.obj : error LNK2028: unresolved token (0A000019) "public: void __clrcall SACommand::setConnection(class SAConnection *)" ([email protected]@@[email protected]@@Z) referenced in function "int __clrcall main(cli::array<class System::String^>^)" ([email protected]@[email protected]@@@Z) 
sqlapi.obj : error LNK2028: unresolved token (0A00001A) "public: __clrcall SAString::~SAString(void)" ([email protected]@[email protected]) referenced in function "int __clrcall main(cli::array<class System::String^>^)" ([email protected]@[email protected]@@@Z) 
sqlapi.obj : error LNK2028: unresolved token (0A00001B) "public: __clrcall SAString::SAString(char const *)" ([email protected]@[email protected]@Z) referenced in function "int __clrcall main(cli::array<class System::String^>^)" ([email protected]@[email protected]@@@Z) 
sqlapi.obj : error LNK2028: unresolved token (0A00001C) "public: void __clrcall SAConnection::Connect(class SAString const &,class SAString const &,class SAString const &,enum SAClient_t,void (__cdecl*)(class SAConnection &,enum SAConnectionHandlerType_t))" ([email protected]@@[email protected]@[email protected]@[email protected][email protected]@@[email protected]) referenced in function "int __clrcall main(cli::array<class System::String^>^)" ([email protected]@[email protected]@@@Z) 
sqlapi.obj : error LNK2028: unresolved token (0A00001D) "public: virtual __clrcall SACommand::~SACommand(void)" ([email protected]@[email protected]) referenced in function [email protected]@[email protected]@@@Z$0 
sqlapi.obj : error LNK2028: unresolved token (0A00001E) "public: __clrcall SACommand::SACommand(void)" ([email protected]@[email protected]) referenced in function "int __clrcall main(cli::array<class System::String^>^)" ([email protected]@[email protected]@@@Z) 
sqlapi.obj : error LNK2028: unresolved token (0A00001F) "public: virtual __clrcall SAConnection::~SAConnection(void)" ([email protected]@[email protected]) referenced in function [email protected]@[email protected]@@@Z$0 
sqlapi.obj : error LNK2028: unresolved token (0A000020) "public: __clrcall SAConnection::SAConnection(void)" ([email protected]@[email protected]) referenced in function "int __clrcall main(cli::array<class System::String^>^)" ([email protected]@[email protected]@@@Z) 
sqlapi.obj : error LNK2019: unresolved external symbol "public: virtual __clrcall SAConnection::~SAConnection(void)" ([email protected]@[email protected]) referenced in function [email protected]@[email protected]@@@Z$0 
sqlapi.obj : error LNK2019: unresolved external symbol "public: virtual __clrcall SACommand::~SACommand(void)" ([email protected]@[email protected]) referenced in function [email protected]@[email protected]@@@Z$0 
sqlapi.obj : error LNK2019: unresolved external symbol "public: void __clrcall SAConnection::Rollback(void)" ([email protected]@@$$FQAMXXZ) referenced in function [email protected]@[email protected]@@@Z$0 
sqlapi.obj : error LNK2019: unresolved external symbol "public: void __clrcall SAConnection::Commit(void)" ([email protected]@@$$FQAMXXZ) referenced in function "int __clrcall main(cli::array<class System::String^>^)" ([email protected]@[email protected]@@@Z) 

我不明白在Win32控制檯模式下的任何錯誤。 我甚至還在其他依賴中添加了庫。

+0

您的代碼並不重要 - 這些是一些內部庫錯誤 – NT88 2011-03-12 07:16:11

回答

1

我還沒有很好地使用C++/CLI,但我認爲你的問題與在這個問題中得到解答error linking to oci libraries from vc++相同。

我還在該線程的底部發現了一條評論http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/44fc45c4-10da-4670-bc5d-2f505ee32fd1,它暗示C++窗體項目必須處於/ clr:pure模式。我猜測這可能與控制檯應用程序有所不同。我還想知道,如果您使用Windows窗體的/ clr模式,您是否正在使用更高版本的Visual Studio?

+0

感謝您的建議,你給的鏈接是有幫助的。我使用了相同的雜注,但在clr普通模式下。 b4我在clr純模式下做了相同的工作,所以我得到了錯誤。使用clr模式而不是clr/pure模式會影響我的表單項目,除了使我能夠使用非託管函數?提前致謝。 – naturmaN 2011-03-12 09:27:33

+0

@naturmaN:我已經在你的其他問題上解釋過了。 – 2011-03-13 08:09:56

+0

@naturmaN我不知道從個人經驗,但[MSDN](http://msdn.microsoft.com/en-us/library/85344whh(v = vs.80).aspx)是我所知道的最好的參考爲了區別。我還在Google搜索時發現了這本書[Expert C++/CLI](http://www.amazon.com/Expert-Visual-CLI-Programmers-Experts/dp/1590597567/ref=sr_1_1?ie=UTF8&s=books&qid=1300003938&sr = 8-1)。在C++ Windows Forms應用程序周圍似乎沒有太多可靠的資源...... – jdasilva 2011-03-13 08:13:27

相關問題