Hi I tried to access SQL server in my Xamarin project.
Here is my code
SqlConnection sqlconn;
string connsqlstring = string.Format("Data Source=PRASANTHSATZ;Initial Catalog=AVOL_POC;Integrated Security=True");
sqlconn = new SqlConnection(connsqlstring);
try
{
sqlconn.Open();
SqlCommand cmd = new SqlCommand("insert into UserDetails values('" + txtUserName.Text + "')", sqlconn);
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
}
finally
{
sqlconn.Close();
}
I m getting following error when it tries to open connection
{System.Data.SqlClient.SqlException: Server does not exist or connection refused. ---> Mono.Data.Tds.Protocol.TdsInternalException: Server does not exist or connection refused. ---> System.Net.Sockets.SocketException: Could not resolve host 'PRASANTHSATZ' at System.Net.Dns.Error_11001 (System.String hostName) [0x00000] in :0 at System.Net.Dns.hostent_to_IPHostEntry (System.String originalHostName, System.String h_name, System.String[] h_aliases, System.String[] h_addrlist) [0x00000] in :0 at System.Net.Dns.GetHostByName (System.String hostName) [0x00000] in :0 at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00000] in :0 at Mono.Data.Tds.Protocol.TdsComm..ctor (System.String dataSource, Int32 port, Int32 packetSize, Int32 timeout, TdsVersion tdsVersion) [0x00000] in :0 --- End of inner exception stack trace --- at Mono.Data.Tds.Protocol.TdsComm..ctor (System.String dataSource, Int32 port, Int32 packetSize, Int32 timeout, TdsVersion tdsVersion) [0x00000] in :0 at Mono.Data.Tds.Protocol.Tds.InitComm (Int32 port, Int32 timeout) [0x00000] in :0 at Mono.Data.Tds.Protocol.Tds..ctor (System.String dataSource, Int32 port, Int32 packetSize, Int32 timeout, Int32 lifeTime, TdsVersion tdsVersion) [0x00000] in :0 at Mono.Data.Tds.Protocol.Tds70..ctor (System.String server, Int32 port, Int32 packetSize, Int32 timeout, Int32 lifeTime, TdsVersion version) [0x00000] in :0 at Mono.Data.Tds.Protocol.Tds80..ctor (System.String server, Int32 port, Int32 packetSize, Int32 timeout, Int32 lifeTime) [0x00000] in :0 at Mono.Data.Tds.Protocol.TdsConnectionPoolManager.CreateConnection (Mono.Data.Tds.Protocol.TdsConnectionInfo info) [0x00000] in :0 at Mono.Data.Tds.Protocol.TdsConnectionPool.GetConnection () [0x00000] in :0 at System.Data.SqlClient.SqlConnection.Open () [0x00000] in :0 --- End of inner exception stack trace --- at System.Data.SqlClient.SqlConnection.Open () [0x00000] in :0 at AVOL_POC.Activity1+<>c__DisplayClass1.b__0 (System.Object param0, System.EventArgs param1) [0x0000d] in c:\Users\Prasanth Satz\Documents\Visual Studio 2012\Projects\AVOL_POC\AVOL_POC\Activity1.cs:34 }
What would be the solution for this