Error in opening the database

Below is the code which i used to open a database, but it ends up with error says Error no: 5002 , says No Resource found.
if i change few other things, it ends up with the error, Authentication was incorrect, Error code no : 10401 or 10402.Not able to open the database itself, it looks so silly for me that why it was not working.

In place of localhost, i was pasting my local ip.i have created credentials in Admin portal too.

Kindly help me out on the same.

// Get the database (and create it if it doesn’t exist).
NSError *error;
CBLDatabase *database = [[CBLDatabase alloc] initWithName:@“mydb” error:&error];

// Create a new document (i.e. a record) in the database.
CBLMutableDocument *mutableDoc = [[CBLMutableDocument alloc] init];
[mutableDoc setFloat:2.0 forKey:@“version”];
[mutableDoc setString:@“SDK” forKey:@“type”];

// Save it to the database.
[database saveDocument:mutableDoc error:&error];

// Update a document.
CBLMutableDocument *mutableDoc2 = [[database documentWithID:mutableDoc.id] toMutable];
[mutableDoc2 setString:@“Swift” forKey:@“language”];
[database saveDocument:mutableDoc2 error:&error];

CBLDocument *document = [database documentWithID:mutableDoc2.id];
// Log the document ID (generated by the database)
// and properties
NSLog(@“Document ID :: %@”, document.id);
NSLog(@“Learning %@”, [document stringForKey:@“language”]);

// Create a query to fetch documents of type SDK.
CBLQueryExpression *type = [[CBLQueryExpression property:@“type”] equalTo:[CBLQueryExpression string:@“SDK”]];
CBLQuery *query = [CBLQueryBuilder select:@[[CBLQuerySelectResult all]]
from:[CBLQueryDataSource database:database]
where:type];

// Run the query
CBLQueryResultSet *result = [query execute:&error];
NSLog(@“Number of rows :: %lu”, (unsigned long)[[result allResults] count]);

// Create replicators to push and pull changes to and from the cloud.
NSURL *url = [[NSURL alloc] initWithString:@“ws://localhost:4984/example_sg_db”];
CBLURLEndpoint *targetEndpoint = [[CBLURLEndpoint alloc] initWithURL:url];
CBLReplicatorConfiguration *replConfig = [[CBLReplicatorConfiguration alloc] initWithDatabase:database target:targetEndpoint];
replConfig.replicatorType = kCBLReplicatorTypePushAndPull;

// Add authentication.
replConfig.authenticator = [[CBLBasicAuthenticator alloc] initWithUsername:@“john” password:@“pass”];

// Create replicator.
CBLReplicator *replicator = [[CBLReplicator alloc] initWithConfig:replConfig];

// Listen to replicator change events.
[replicator addChangeListener:^(CBLReplicatorChange *change) {
if (change.status.error) {
NSLog(@“Error code: %ld”, change.status.error.code);
}
}];

// Start replication
[replicator start];

Your question is somewhat unclear. Are you saying this happens during replication? The error codes would indicate either an unknown web address, or problems with authentication. I would not use the “admin portal” (not sure what you are referring to here) and instead either use the sync gateway config or the REST API to create your users.

Hello borrrden,

I was not able to open the database even it exists in my admin portal.Here i need a data synchronisation method like a mail client app.We would like to create a DB in Couch base, so our web and iOS will contact the same server to achieve data synchronisation while sending/receiving an email.

Please paste the exact error message. In that NSLog call, log the NSError object itself with %@, not just the code.