0
我在WebService中遇到了一些問題。當我在數據庫中執行我的查詢,返回很好,但是當我通過服務(在線)執行,則返回錯誤 System.Data.SqlClient.SqlException: Incorrect syntax near '<'.
查詢在數據庫中執行,但在WebService中執行時不執行
CODE
[WebMethod]
public XmlDocument listagemCredenciadasCoordenadaGeografica(string latitude, string longitude, float raio)
{
try
{
string s = "SELECT San_Filial.Credenciada_Id "
+ "FROM San_Filial "
+ "WHERE (San_Filial.Excluido = 0) "
+ "AND (San_Filial.Credenciada_Id NOT IN (62, 85, 1, 68, 10, 151, 152, 153, 154, 155)) "
+ "AND San_Filial.lat != '0' "
+ "AND San_Filial.lat IS NOT NULL "
+ "AND San_Filial.ddd IS NOT NULL "
+ "AND ACOS(COS(RADIANS(RTRIM(LTRIM(San_Filial.lat)))) * "
+ "COS(RADIANS(convert(float," + latitude + "))) * "
+ "COS(RADIANS(RTRIM(LTRIM(San_Filial.lon))) - "
+ "RADIANS(convert(float," + longitude + "))) + "
+ "SIN(RADIANS(RTRIM(LTRIM(San_Filial.lat))) * "
+ "SIN(RADIANS(convert(float," + latitude + ")))) * 6380 < " + raio + " ";
XmlDocument xml = new XmlDocument();
xml.LoadXml(ExecuteStrQuery(s, "Table").GetXml());
return xml;
}
catch (Exception ex)
{
throw ex;
}
}
public static DataSet ExecuteStrQuery(string Query, string NameTable)
{
neticonn.ConexaoWebServices conn = new neticonn.ConexaoWebServices();
SqlConnection c = new SqlConnection(conn.novaConexao("netservicemobile"));
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
try
{
SqlCommand cmd = new SqlCommand(Query, c);
cmd.CommandType = CommandType.Text;
da = new SqlDataAdapter(cmd);
da.Fill(ds, NameTable);
return ds;
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex);
}
finally
{
try
{
if (c.State != ConnectionState.Closed)
{
c.Close();
c.Dispose();
da.Dispose();
}
}
catch
{
}
}
}
如果你不知道之前:ASMX是一種過時的技術,和不應該用於新的開發。 WCF應該用於Web服務客戶端和服務器的所有新開發。一個暗示:微軟已經在MSDN上退役了[ASMX Forum](http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/threads)。 – 2013-02-27 19:09:33
'c.Dispose();'和'da.Dispose();'不需要。 – Brian 2013-02-27 19:09:44
另外,千萬不要使用'throw ex;'。使用'throw;'重新拋出一個異常,或者更好的是,不要把它放在第一位。 – 2013-02-27 19:09:58