[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

I need to know how to connect to my host server's sql/server 2005 database , from my Iphone.

Posted on 2011-10-13
5
Medium Priority
?
1,126 Views
Last Modified: 2012-12-23
I need to know how to connect to my host server's sql/server 2005 database , from my Iphone.
I have an Iphone app written in NSbasic and the code for importing and exporting data is below.

I need to know how to connect to my host servers database?
I would like to query the external database (sql/server) and import the query result into the Iphone's Sqlite's database.



 


Function JSONImport()
  Dim data, sqlList, q
  file=ReadFile("customers.json")
  data=JSON.parse(file.responseText)
  DB = SqlOpenDatabase("customers.db","1.0","My Customer Database")
  q=Chr(34)
  If DB<>0 Then
    sqlList=[]
    sqlList[0]=["DROP TABLE customerData;",,skipError]
    sqlList[1]=["CREATE TABLE IF NOT EXISTS " & "customerData('name', 'address1', 'address2', 'age', 'sales', PRIMARY KEY('name') );"]

    For i = 0 To UBound(data)-1
      Name    = q & data[i].name & q
      Address1= q & data[i].address1 & q
      Address2= q & data[i].address2 & q
      Age     = data[i].age
      Sales   = data[i].sales
      s = Join([Name, Address1, Address2, Age, Sales],",")
      sqlList[i+2]="INSERT INTO customerData (name, address1, address2, age, sales) VALUES ( " & s & ");"
    Next

    sqlList[i+2]=["SELECT * from customerData ORDER BY name;", dataHandler]
    Sql(DB, sqlList)
  End If
End Function

Function JSONExport()
  Dim i
  recs=DBRecords.rows.length
  Dim data(recs)
  For i=0 To recs-1
    data[i]=DBRecords.rows.item(i)
  Next
  JSONExport=JSON.stringify(data)
End Function

Open in new window

0
Comment
Question by:westdh
  • 2
  • 2
5 Comments
 
LVL 20

Expert Comment

by:darbid73
ID: 36966913
When a program "connects" to a database server in the fashion you are thinking about it uses an intermediary program or driver.  You probably now words like ODBC driver, but there are many others.  Oracle also has their own drivers.  Even a MSAccess front end needs a driver to talk to a SQL Server.

So what you are looking for in your question is this.

Now I have seen your question as you have made it iPhone related, but I did not even know this NSBasic existed.  It looks cool, as I have used and know VB and VBA very well.  Looking around I have seen this Hot to connect to a server.  But what I am not sure about is whether this can be used when you later convert/compile your code to a native iphone app.  If it does I would be surprised.

If you were writing the app in objective C with xCode I would be suggesting you look here ODBC Driver for iPHone.  BUt really the widely accepted and with no doubt the way that 99% of people connect to a data base is through a webservice layer.  You probably have seen words like API webservice with XML or JSON responses (Google etc have many APIs now for weather and finance and just about anything) - .NET has WCF RESTful services.  This is how most iOS apps would get and send information to a database.
0
 

Author Comment

by:westdh
ID: 36967699
Yes NSBasic can be convert to IOS or many other mobile phones using PhoneGap which is included in NSBasic.
 
this function I am using imports a sample database into sqlite.
what i like to know is how can I connect JSON to my Host mssql/server database ms2005

Function JSONImport()
  Dim data, sqlList, q
  file=ReadFile("customers.json")
  data=JSON.parse(file.responseText)
  DB = SqlOpenDatabase("customers.db","1.0","My Customer Database")


0
 
LVL 20

Accepted Solution

by:
darbid73 earned 2000 total points
ID: 36967760
what i like to know is how can I connect JSON to my Host mssql/server database ms2005
Either I am behind in my learning (which is possible) or I think we have a few concepts to understand.

JSON is a format for showing data.  XML is also used for the same purposes.  JSON comes from or is like maybe a little more by the Java crowd (personal opinion)

So to get data from your MSSQL server - and put it into SQLite in your app with the help of JSON you have missed out some steps.

You need to learn what data serialization.  When you make a query on your MSSQL database and get a result it needs to be serialized into text form and that format you would like is JSON.  Then this text file which is in JSON format can be read by a JSON parser and you can then add it to SQLite (I would suggest with CoreData) but maybe that is not a word you know in NSBasic.
0
 

Author Closing Comment

by:westdh
ID: 36968263
Thanks for the help
0
 
LVL 2

Expert Comment

by:chrisryhal
ID: 38717122
westdh,

I know this is an old thread, but you wouldn't have an example on how I can connect to my WCF service using NSBasic would you?

My response from WCF is JSON.

I'm fairly new to NSBasic and really just demoing it more or less but if I can get it to connect and consume my JSON from my WCF, it might be very beneficial to me.
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Set up iPhone and iPad email signatures to always send in high-quality HTML with this step-by step guide.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question