Issues with SQLAPI++

So, I'm trying to work with this API, but it keeps telling me my sqlapi.dll is missing from my computer. I can literally see the file though. I moved a copy to my system32 as well, and still no luck. I tried some regvsr32 run command for it and nothing. Says sqlapi.dll is not compatible with 64 bit
Nevermind, moved it into my VS folder and it runs. Now it just doesn't actually connect to the server. Not sure what im doing wrong here, the documentation for this api is next to nothing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include "SQLAPI.h"

using std::cout;
using std::cin;
using std::endl;

int main(int argc, char* argv[])
{
	SAConnection connection;	//Creates connection object

	try
	{
		connection.Connect(
			"Individual",
			"Jared-Laptop\\Jared",
			"" );

		cout << "Connection created.\n";

		//Disconnect is optional. Destructor will auto-disconnect.
		connection.Disconnect();

		cout << "Connection terminated.\n";
	}
	catch(SAException &x)
	{
		try
		{
			connection.Rollback();
		}
		catch(SAException &x)
		{
		}
		cout << x.ErrText() << endl;
	}
	cout << "Connection failed\n";
	return 0;
}
Updated code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include "SQLAPI.h"

using std::cout;
using std::cin;
using std::endl;

int main(int argc, char* argv[])
{
	SAConnection connection;	//Creates connection object

	try
	{
		cout << "Initiating connection...\n";
		connection.setOption( "UseAPI" ) = "OLE DB";
		connection.setClient( SA_SQLServer_Client );
		connection.Connect(
			"(local)\TESTSERVER@Individual",
			"Jared-Laptop\\Jared",
			"");

		cout << "Connection created.\n";

		//Disconnect is optional. Destructor will auto-disconnect.
		connection.Disconnect();

		cout << "Connection terminated.\n";
	}
	catch(SAException &x)
	{
		try
		{
			connection.Rollback();
		}
		catch(SAException &x)
		{
		}
		cout << "Connection failed with code ";
		cout << x.ErrText() << endl;
	}
	return 0;
}


Connection still fails.
Shameless self bump
Let's use this thread, as at least has code.
1
2
		cerr << "Connection failed with code ";
		cerr << x.ErrText() << endl;
¿output?
Thanks for the reply ne555, I've been waiting for awhile for someone to answer. I've had no luck in searching for the solution.

Anyway, I tried using cerr, and it still kicks out some hexadecimal number
Try casting it.
cerr << (const char*) (x.ErrText()) << endl;

Edit: It doesn't make sense, just saw that in the examples.
Last edited on
I gave this a try last nite, with probably the same issue as ResidentBiscuit. The cast makes a big difference, my error is now
Connection failed with code 28000 Login failed for user 'Sean'
18456
The 18456 is x.ErrNativeCode().
I dont think its the database as I can connect to it from c#, but that code I used doesn't require password. Perhaps the password is an issue?
Oh wow yea casting helped a ton. I too got the same error message. Any thoughts as to how to fix it?
It is the username and password, leave them both blank and you should be able to connect.
1
2
3
4
5
connection.Connect(
	"testDB",
	"",
	"",
	SA_SQLServer_Client);
Last edited on
Wow that worked without any issue. Any idea as to why that worked? I'm trying to make a back end to a database management system, and I feel like it would be good if users could actually log in
From http://www.sqlapi.com/ServerSpecific/SQLServer_OleDb.html#Connecting%20to%20a%20database

sUserID. A string containing a user name to use when establishing the connection. If sUserID parameter is empty, SQLAPI++ Library requests a secure, or trusted, connection to SQL Server.
So this sounds like if I wanted to log in as an admin, I'm just out of luck. I'm not sure what permissions a
secure or trusted connection
has
Topic archived. No new replies allowed.