Connect to SQL Server DB

This is the 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
43
44
45
46
void GetConnected()
{
    SQLHANDLE henv;
    SQLRETURN rc;
    SQLHANDLE hconn;
    SQLSMALLINT bufsize=0;
    SQLINTEGER nativeerror=0;
    SQLSMALLINT textlen=0;
    unsigned char connStrOut[256];
    SQLWCHAR sqlstate[32];
    SQLWCHAR message[256];
 
    rc = SQLAllocEnv(&henv);
    if (rc != SQL_SUCCESS)
    {
        printf("\nSQLAllocEnv call failed.");
        return;
    }
 
    rc = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hconn);
    if (rc != SQL_SUCCESS)
    {
        SQLFreeHandle(SQL_HANDLE_ENV, henv);
        printf("\nSQLAllocHandle call failed.");
        return;
    }
 
    rc = SQLDriverConnect(hconn, NULL, (SQLWCHAR*)TEXT("DRIVER=SQL Server;SERVER=MyServer,1433;UID=Administrator;PWD=Pass;"), SQL_NTS, NULL, 256, &bufsize, SQL_DRIVER_NOPROMPT);
 
    if (bufsize!=0)
    {
        printf("Connected successfully.\n");
        SQLDisconnect(hconn);
    }
    else
    {
        rc = SQLGetDiagRec(SQL_HANDLE_DBC, hconn, 1, sqlstate, &nativeerror, message, 256, &textlen);
 
        printf("SQLDriverConnect failed.\n");
        if (rc!=SQL_ERROR)
            printf("%s=%s\n", (CHAR *)sqlstate, (CHAR *)message);
    }
 
    SQLFreeHandle(SQL_HANDLE_DBC, hconn);
    SQLFreeHandle(SQL_HANDLE_ENV, henv);
}


I get error:
"[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'SP2010-EBS\Administrator'."

I can connect to my DB with Management Studio, but I can't through c++ code. I've tried many different users. Can anyone help me?
Ok, I am sorry for this, but it bothered me for hours, and I've solved it just now. All that I had to do is add "Trusted_Connection=yes" to connection string.
Topic archived. No new replies allowed.