I need to connect an SQL server via a mobile app. It can be directly implemented because its private. Not open source or publicly available. How can I do this and what libraries do I use? I am using xamarin
CodePudding user response:
Connecting to a SQL server can be done via System.Data.SqlClient package.
You need to config the connect setting in your code-behind;
The server dbname is the database in your SQL server and the server name, you need to use ipconfig
in the cmd and the IPv4 address is the server name.Last but not least, you need to set the server_username and password in SQL server.Below is the code snippet for your reference.
string server_dbname = "your_dbname_in_SQLserver";
string server_name = "192...";
//ipconfig -- IPv4 Address
string server_username = "";
string server_password = "";
string sqlconn = $"Data Source={server_name};Initial Catalog ={server_dbname};User Id = {server_username};Password={server_password};Trusted_Connection = true";
SqlConnection sqlConnection = new SqlConnection(sqlconn);
sqlConnection.Open();
Kind reminder: It is not recommended to have direct access from a mobile app to your SQL server.If the SQL servers get hacked,your data will get lost.
CodePudding user response:
Build a web service for it that acts as service broker between your data and your xamarin mobile app. Add security to it then make it accessible from the internet and you're good to go.