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

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

westdhAsked:
Who is Participating?
 
darbid73Connect With a Mentor Commented:
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
 
darbid73Commented:
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
 
westdhAuthor Commented:
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
 
westdhAuthor Commented:
Thanks for the help
0
 
chrisryhalCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.