I am using MapInfo V16, Mapbasic 16, MSSQL and I am very much new to Mapbasic like I started to work on it for a week.
I want to connect to MSSQL server and access X tables from Database A without letting the user pass any usernames and passwords to connect to the database. The user should not have any choice to select any other than X tables.
Dim nConn As Integer
Dim sMyDSN, sMyUsername, sMyPassword As String
sMyDSN = "MySQLServer"
sMyUsername = "PEM"
sMyPassword = "ABCDEF"
nConn = Server_Connect("ODBC", "DSN=" & sMyDSN & "; UID=" & sMyUsername & "; PWD=" & sMyPassword)
And then to select the tables
Register table "ROADS"
Type ODBC
Connection Handle nConn
Toolkit "ODBC"
Table "Select * From DB.ROADS"
Into "C:\test\ROADS.tab"
Open Table "C:\test\ROADS.tab"
I could see this example is for MySQL but how I do I recreate the same for MSSQL? And in this example, For DSN do we have to give the DSN name along with the location?
Only DSN I know is a file that gets created when we create aODBC connection with MSSQL with the following details
[ODBC]
DRIVER=SQL Server
UID=sa
DATABASE=Test
WSID=KRISHNA
APP=MapInfo® Pro
SERVER= x.x.x.x
Description=ABCDEF
Now I would like to know how do we connect to the specific tables without letting the user see the credential window.
I tried like this
Keeping one DSN file by giving UID and PWD and calling the DSN with
Dim hdbc As Integer
hdbc = Server_Connect("ODBC", "SRVR=IP;UID=username;PWD=password")
But when I use this, MapInfo is still opening a window to select the DSN file as below
See Attachment
and then SQL login
See Attachment
Then we need to select the schema then Table and access type
See Attachment
I just wanted to remove the GUI part here and make the connection with Tables
Looking forward to seeing the Mapbasic code that can help me to make the connection with MSSQL database " Test" and connect to tables "xx,xy,xyz and abc " with DSN name " Grid.DSN"
Thanks in advance.