Direct connection to the remote existing database from Swift

I am writing an application in Swift that should be able to interact with the external Database.

The database is already created, and it exists on the remote MS SQL server. The database is not exposed as a web service, instead I can only access it through the connection string I was given.


Connection string is formatted like so:

data source={server_domain}\SQL2012,3000;initial catalog={my_catalog};persist security info=True;user id={username};password={password};


I have found that such problems are usually solved by writing the server-side script that queries the Database, and then retrieves the data in JSON or XML format that can easily be parsed into objects. However, I don't have such option since I have no access to the server-side, the server is located at my University and I do not own it.


That said, I would need to connect to the DB directly, and not by using some PHP server-side scripts or similar stuff.

I have done similar thing in .NET using NHibernate, where the connection string was used to connect to the database, and all DB manipulation was easily done from the C# code.


How should one do that in Swift? Any advices on how I should approach this task? Could Core-Data help in any way?

If you do a web search for

Swift "MS SQL Server"

one of the search results should a page titled

SQLClient: A Native Microsoft SQL Server Library for iOS


That's a good starting point. CoreData is NOT A GENERIC DATABASE WRAPPER.

Yes, but this library is in Objective-C. Is there any option to do so in Swift?

Not natively.


Your best bet would be to use the Objective-C library from Swift.

The library is written in Objective-C. That doesn't matter.


Thanks to the amount of work Apple's done in the Objective-C/Swift interfaces, you get to write code in Swift that calls Objective-C code all day long and not notice.

Direct connection to the remote existing database from Swift
 
 
Q