ldap_bind(): Unable to bind to server - ldap

I have below code and I am getting error:
Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server in C:\xampp\htdocs\ldap.php on line 17
<?php
$ldapconfig['host'] = "dsua1.company.com";
$ldapconfig['port'] = 636;
$ldapconfig['basedn'] = "cn=userid,ou=Applications,ou=Company,ou=Services,dc=iM-2,dc=com";
$ldapconfig['binddn'] = "userid";
$ldapconfig['bindpw'] = "password";
$ldapconn=ldap_connect($ldapconfig['host'],$ldapconfig['port']);
ldap_bind($ldapconn, $ldapconfig['binddn'], $ldapconfig['bindpw']);
?>

Since you specified port 636, I assume that you need an SSL-connection to the server. This is achieved by:
ldap_connect("ldaps://".$ldapconfig['host']."/");
Otherwise it would try to send plaintext data which would not be accepted on an SSL-socket.
Furthermore, try this after ldap_connect() and before ldap_bind():
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
Sometimes an error occurs when an incorrect protocol version is used, 3 is common now, but not standard for the ldap_* PHP function family.

Related

How do I handle session id context uninitialized in Thrift

sorry to bother you guys,
I have a Thrift server program in c++. Whenever a client connects to me, the handshake succeeds, as does the first Thrift command sent, but the second command sent fails with the error "session id context uninitialized".
The client's next command re-establishes the connection and succeeds, but the fourth will fail again with "session id context uninitialized".
The exact error is
TConnectedClient died: SSL_accept: session id context uninitialized (SSL_error_code = 1)
TConnectedClient input close failed: session id context uninitialized (SSL_error_code = 1)
TConnectedClient output close failed: session id context uninitialized (SSL_error_code = 1)
every 'even' command
My problem seems similar to THIS, but I can't seem to figure out how to change the context of my session to set the SSL_OP_NO_TICKET flag.
I tried adding a ServerEventHandler, but I don't think I can change the serverContext that is present there.
Can anyone help me?
Below is the section of main() where I declare and start the server. If more information is needed, please ask. (sorry if I typo-ed any code, I had to retype by hand it here)
::apache::thrift::stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactoryT<TBufferBase>());
::apache::thrift::stdcxx::shared_ptr<My_svrHandler> handler(new My_svrHandler());
::apache::thrift::stdcxx::shared_ptr<TProcessor> processor(new My_svrProcessor(handler));
::apache::thrft::stdcxx::shared_ptr<TSSLSocketFactory> sslSocketFactory(new TSSLSocketFactory(SSL::TLSv1_2));
sslSocketFactory->loadCertificate(certLocation);
sslSocketFactory->loadPrivateKey(keyLocation);
sslSocketFactory->loadTrustedCertificates(CALocation);
sslSocketFactory->authenticate(true);
::apache::thrift::stdcxx::shared_ptr<TServerSocket> serverSocket(new TSSLServerSocket(9090, sslSocketFactory));
::apache::thrift::stdcxx::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
::apache::thrift::stdcxx::shared_ptr<apache::thrift::server::Tserver> server;
::apache::thrift::stdcxx::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(10);
::apache::thrift::stdcxx::shared_ptr<PlatformThreadFactory> threadFactory = ::apache::thrift::stdcxx::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
threadManager->threadFactory(threadFactory);
threadManager->start();
server.reset(new TThreadedPoolServer(processor, serverSocket, transportFactory, protocolFactory, threadmanager));
if(server.get() != NULL)
{
apache::thrift::concurrency::PlatformThreadFactory factory;
::apache::thrift::stdcxx::shared_ptr<apache::thrift::concurrency::Runnable> serverThreadRunner(server);
::apache::thrift::stdcxx::shared_ptr<apache::thrift::concurrency::Thread> thread = factory.newThread(serverThreadRunner);
signal(SIGPIPE, SIG_IGN);
thread->start();
while(1){}
server->stop();
thread->join();
server.reset();
}

WTSVirtualChannelOpenEx sometimes failed?

I have a rdp plugin used in my C# AxMSTSCLib.AxMsRdpClient7NotSafeForScripting rdp client:
rdp.AdvancedSettings8.PluginDlls = "{7d413ce8-a0a1-42d9-a67b-6d4be4af17c5}";
When I open the channel on server side:
channelHandle = Win32API.WTSVirtualChannelOpenEx(Win32API.WTS_CURRENT_SESSION,
Marshal.StringToHGlobalAnsi(APP_CHANNEL_NAME),
Win32API.WTS_CHANNEL_OPTION_DYNAMIC | 4);
Sometimes ok, sometimes failed with error code = 0x31, no more error description. Is there any problem with my code?

Excel power query, error handling for fallback connection/OleDb data source

I have a PowerQuery connected to DB2 Data Source, but because of some kind of load balancing the DB Server changes periodically (ip also changes), There is no way for me to know beforehand which data source (IP), I should use until I try it and see that it errors out, then I have to use the other one, I googled for error handling in PowerQuery and found some examples of error handling but this examples did not apply to my case, most of them handled errors AFTER the connection was made or were preventing errors on missing columns or files not found, I tried to adjust the examples to my case but was not able to.
What I want is just try one IP and if it fails then use the other one.
let
//fParametros("ParamQuery",1) is the "standard" Server/Ip address (provider=IBMDADB2.IBMDBCL1;data source=CP3;location=pn8us7ldbcp3.us.mycompany.com:5912)
dbSource = fParametros("ParamQuery",1),
//fParametros("ParamQuery",5) is the "Alternate" Server/Ip address (provider=IBMDADB2.IBMDBCL1;data source=CP3;location=pn8us7ldbcp3h.us.mycompany.com:5912)
AltdbSource = fParametros("ParamQuery",5),
pOrden = Text.From(fParametros("ParamQuery",2)),
//Create the query
dbQuery = "SELECT SAPCP3.vbak.VBELN SO , SAPCP3.vbap.posnr PoLine , SAPCP3.vbep.ETENR Sch_Line , SAPCP3.vbap.matnr Part_Number,SAPCP3.makt.maktx Description,SAPCP3.vbap.kwmeng Qty ,SAPCP3.vbep.BMENG Conf_qty ,SAPCP3.vbap.vrkme UOM ,SAPCP3.vbap.netpr SalesPrice ,SAPCP3.vbap.kpein LotSize FROM SAPCP3.vbak JOIN SAPCP3.vbap ON SAPCP3.VBAp.VBELN = SAPCP3.VBAK.VBELN JOIN SAPCP3.vbep ON SAPCP3.vbep.vbeln = SAPCP3.vbak.vbeln AND SAPCP3.vbap.posnr = SAPCP3.vbep.posnr JOIN sapcp3.makt ON sapcp3.vbap.matnr=sapcp3.makt.matnr WHERE SAPCP3.VBAK.VKORG = '4000' AND (SAPCP3.vbep.edatu >= '20190701') AND SAPCP3.vbak.VBELN ="& pOrden & " ORDER BY SAPCP3.vbak.VBELN",
//Get the data
Source = OleDb.DataSource(dbSource, [Query=dbQuery]),
//Failed Attempt to handle the error:
TestForError= try Source,
//next line does not work, I get error saying Source is already defined/declared
Source = if TestForError[HasError] then OleDb.DataSource(AltdbSource, [Query=dbQuery]) else OleDb.DataSource(dbSource, [Query=dbQuery])
in
Source
I also Tried the following:
.
.
.
//Get the data
Source = OleDb.DataSource(dbSource, [Query=dbQuery]),
//Failed Attempt to handle the error:
TestForError= try Source,
Output = if TestForError[HasError] then OleDb.DataSource(AltdbSource, [Query=dbQuery]) else OleDb.DataSource(dbSource, [Query=dbQuery])
in
Output
//This last part works if the dbSource is correct, but if it is not it doesnt catch the error and gives me the Connection error shown below:
DataSource.Error: OLE DB: SQL30081N A communication error has been detected. Communication protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was detected: "172.16.0.1". Communication function detecting the error: "connect". Protocol specific error code(s): "10061", "", "". SQLSTATE=08001
Details:
DataSourceKind=OleDb
DataSourcePath=data source=CP3;location=pn8us7ldbcp3.us.mycompany.com:5912;provider=IBMDADB2.IBMDBCL1
Message= SQL30081N A communication error has been detected. Communication protocol being used: "TCP/IP". Communication API being used: "SOCKETS". Location where the error was detected: "172.16.0.1". Communication function detecting the error: "connect". Protocol specific error code(s): "10061", "", "". SQLSTATE=08001
ErrorCode=-2147467259
I want to connect to dbSource (172.16.0.1) and if it is not possible then connect to AltdbSource (172.16.0.2)
Currently I have 2 identical excel sheeets and user needs to open one or the other if he gets the connection error, I want it to change automatically.
I'm guessing that TestForError = try OleDb.DataSource(BadSource) isn't working because OleDb.DataSource(...) returns a table value than only produces an error when trying to enumerate rows.
What if you change TestForError to drill into the first row if it exists:
TestForError= try Source{0}?,
If that still doesn't work, next try indexing into a table cell in the first row.

Debug and Cannot Open Connection to SQL

When debugging in SQL, I get the following exception :-
System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'
When I then set next statement and run the statement again, it works. It also works when I'm running the application standalone as a compiled application. Anyone know why this causes an error only when in debug.
The connection is to a remote database sited off-site, not to the local database.
Data Source=xx.xx.xx.xx;Initial Catalog=TheDatabase;User ID=MasterUser;Password=AsIfIMGoingToPostThat
Your help, appreciated.
This is my function to connect...
Public Sub New(ByVal strConnect As String)
Try
dbConnect = New System.Data.SqlClient.SqlConnection(strConnect)
dbConnect.Open()
objParams = New List(Of SqlClient.SqlParameter)
m_bIsConnected = True
Catch exc As Exception
m_bIsConnected = False
Finally
End Try
It looks like your local connection doesn't default to named pipes but your compiled version will try (or is allowed to use TCP/IP). The error shows that it may be expecting named pipes.
Try putting this "np:" in the Data Source in your connection string:
Data Source=np:xx.xx.xx.xx; ...
To get it to connect first time, it looks like I need to add "Network Library=DBMSSOCN;" to connect in debug. t.b.h., Have no idea why...

SQL Anywhere connection error: The driver doesn't support the version of ODBC behavior that the application requested

I'm trying to connect to a SQL Anywhere 5 database (I know it's olllld!) with a .NET 3.5 app in WinXP and it works fine from a stand alone console app. But when I run the exact code in a plugin ,running off a separate AppDomain, (the only difference I can tell between the two) with the following code, I get the errors further below.
BTW Both are executed as the SAME user.
using (OdbcConnection connection =
new OdbcConnection(strConnect))
{
OdbcCommand command = new OdbcCommand(query, connection);
command.CommandType = CommandType.Text;
DataTable posRecordsTable = new DataTable();
connection.Open();
OdbcException Exception returns the following errors:
Index #0
Message: [Sybase][ODBC Driver]Unable to connect to database server: database engine not running
Index #1
Message: [Sybase][ODBC Driver]Invalid connection string attribute
Index #2
Message: [Sybase][ODBC Driver]Invalid connection string attribute
Index #3
Message: [Microsoft][ODBC Driver Manager] The driver doesn't support the version of ODBC behavior that the application requested (see SQLSetEnvAttr).
Does the driver on your AppDomain have the same configuration as your stand alone box? I think checking the similarity of the environments will help you. Usually such errors are resolved by looking at the config files from where the driver reads its information. Dont know much about SQL Anywhere, but in general, I've come across such issues and I fixed them by altering the connection information or the configuration file.