Android Question Connect to msslql server - sql.bsite.net\mssql2016

fasilosman

Active Member
Licensed User
Longtime User
Hi

I have created a MSSql database in https://freeasphosting.net website
It provided my a mssql database as follows

  • Server Name: sql.bsite.net\MSSQL2016
  • SQL database: SampleDB
  • SQL Username: dbuser
  • SQL password: xxxxxxx
The examples in the forum helped me in connecting other mssql database. But the above saver name with "\" does not recognized as server.
I can connect with slq server management studio.
Any ideas to overcome this issue
 

fasilosman

Active Member
Licensed User
Longtime User
Instead of backward slash, have you tried forward slash?
Yes I tried. But it didn't work.
If you can pls try it with following credentials
  • Server Name: sql.bsite.net\MSSQL2016
  • SQL Database name: phazilosman_SampleDB
  • SQL Username: phazilosman_SampleDB
  • SQL Password: 123456
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Here is my code:

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private SQL1 As JdbcSQL
End Sub

Public Sub Initialize

End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    SQL1.Initialize2("net.sourceforge.jtds.jdbc.Driver", "jdbc:jtds:sqlserver://sql.bsite.net;databaseName=phazilosman_SampleDB;instance=MSSQL2016;integratedSecurity=true", "phazilosman_SampleDB", "123456")
End Sub

Private Sub Button1_Click
    Dim strSQL As String = $"SELECT TOP 10 * FROM People"$
    Dim RS As JdbcResultSet = SQL1.ExecQuery(strSQL)
    Do While RS.NextRow
        Log(RS.GetString2(0))
    Loop
    RS.Close
End Sub
 
Last edited:
Upvote 0

fasilosman

Active Member
Licensed User
Longtime User
Here is my code:

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private SQL1 As JdbcSQL
End Sub

Public Sub Initialize

End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    SQL1.Initialize2("net.sourceforge.jtds.jdbc.Driver", "jdbc:jtds:sqlserver://sql.bsite.net;databaseName=phazilosman_SampleDB;instance=MSSQL2016;integratedSecurity=true", "phazilosman_SampleDB", "123456")
End Sub

Private Sub Button1_Click
    Dim strSQL As String = $"SELECT TOP 10 * FROM People"$
    Dim RS As JdbcResultSet = SQL1.ExecQuery(strSQL)
    Do While RS.NextRow
        Log(RS.GetString2(0))
    Loop
    RS.Close
End Sub
I tried. But it is not responding anything.

Can you please upload a sample project file.
 
Upvote 0

fasilosman

Active Member
Licensed User
Longtime User
I changed the code as follows
B4X:
        sql1.InitializeAsync("sql1","net.sourceforge.jtds.jdbc.Driver", "jdbc:jtds:sqlserver://sql.bsite.net;databaseName=phazilosman_SampleDB;instance=MSSQL2016;integratedSecurity=true", "phazilosman_SampleDB", "123456")

Now its working fine.
Thanks for the support
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I changed the code as follows
B4X:
        sql1.InitializeAsync("sql1","net.sourceforge.jtds.jdbc.Driver", "jdbc:jtds:sqlserver://sql.bsite.net;databaseName=phazilosman_SampleDB;instance=MSSQL2016;integratedSecurity=true", "phazilosman_SampleDB", "123456")

Now its working fine.
Thanks for the support
You are right. I tested only in Debug mode. In Release mode, it will fail using Initialize2. We need to use Async methods.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private SQL1 As JdbcSQL
End Sub

Public Sub Initialize

End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    SQL1.InitializeAsync("sql1", "net.sourceforge.jtds.jdbc.Driver", "jdbc:jtds:sqlserver://sql.bsite.net;databaseName=phazilosman_SampleDB;instance=MSSQL2016;integratedSecurity=true", "phazilosman_SampleDB", "123456")
    Wait For sql1_Ready (Success As Boolean)
    If Success Then
        Log("Connected")
        ToastMessageShow("Connected", False)
    Else
        Log(LastException)
    End If
End Sub

Private Sub Button1_Click
    Dim strSQL As String = $"SELECT TOP 10 [First Name], [Last Name], [Department] FROM [People]"$
    Dim SenderFilter As Object = SQL1.ExecQueryAsync("SQL1", strSQL, Null)
    Wait For (SenderFilter) SQL1_QueryComplete (Success As Boolean, RS As JdbcResultSet)
    If Success Then
        Dim Columns As String
        For i = 0 To RS.ColumnCount - 1
            Columns = Columns & IIf(i > 0, " | ", "") & RS.GetColumnName(i)
        Next
        Log(Columns)
        Do While RS.NextRow
            Log($"${RS.GetString2(0)} | ${RS.GetString2(1)} | ${RS.GetString2(2)}"$)
        Loop
        RS.Close
    Else
        Log(LastException)
    End If
End Sub
 

Attachments

  • JDBC_MSSQL.zip
    14.3 KB · Views: 28
Upvote 0
Top