Home > Net >  Webapi I think through customer request parameters to dynamic selection to operate database, I test,
Webapi I think through customer request parameters to dynamic selection to operate database, I test,

Time:01-10

Because of large amount of data, the unit to create a new database every year, but also the old database query, I want to use according to the parameters from build connection to realize this requirement, but the study found that problem, the following code in the native debugging use localhost: 6948/API/Test/GetTest? StrYGNo=00002 to perform there is no problem, but a release to use IP to try out the "ObjectContent ` 1" type to serialize content type "application/json; Response body charset=utf-8 ", " mistake, I searched the Internet said in WebApiconfig cs add GlobalConfiguration. Configuration. Formatters. XmlFormatter. SupportedMediaTypes. The Clear (); Is ok, but the measured useless, after repeated testing found that as long as the connection in which two words make statements will go wrong, a remove those words was no problem, could you tell me how to solve, or any other way to meet this demand, will not be a database to build a web site.

The namespace LinlongHrmWebApi. Controllers
{
Public class TestController: ApiController
{
[HttpGet]
Public IEnumerable GetTest (string strYGNo)
{
SqlConnection SqlConnection=new SqlConnection (" Data Source=Myserver; Initial Catalog=myData; Integrated Security=True; User Id=sa; Password="aaa");

SqlConnection. The Open ();//as long as have the two words of error

String SQL="select ygno, ygname from ygzl where ygno=N '" + strYGNo +"' ";
The DataTable dt=new DataTable ();
SqlDataAdapter SqlDataAdapter=new SqlDataAdapter (SQL, sqlConnection);
SqlDataAdapter. The Fill (dt);

Yield return JsonConvert. SerializeObject (dt);
}
}
}

CodePudding user response:

Remove the two sentence was no problem, where the sqlConnection behind?
Sql server doesn't work for a long time, can use mysql table partitioning + plans to achieve a file, every day
You can search a SQL Server table partitioning
https://www.cnblogs.com/knowledgesea/p/3696912.html