I created a serverless project referencing the System.Data.Sqlclient assembly. I first noticed when I published I got an error “Cannot find System.Data.Sqlclient”. I copied this file from the runtime folder under the win directory to the publish directory. This solved the problem of not beiing able to find the assembly after publishing.
However I now get an error “The type initializer for ‘System.Data.SqlClient.TdsParser’ threw an exception.”. My connect string is fine since I created the same lambda function and published with AWS toolkit and all works fine.
Any suggestions would be greatlly appreciated. Here is a simple function to demonstrate.
public class Handler
{
public LambdaProxyResponse Search(LambdaProxyRequest request, ILambdaContext context)
{
var connString = "Server=...;Database=...;User Id=...;Password=....";
try
{
using (SqlConnection conn = new SqlConnection(connString))
{
return new LambdaProxyResponse
{
body = "success",
statusCode = 200
};
}
}
catch (Exception ex)
{
return new LambdaProxyResponse
{
body = ex.Message,
statusCode = 500
};
}
}
}
public class LambdaProxyRequest
{
public string httpMethod { get; set; }
public string path { get; set; }
public string resource { get; set; }
public string body { get; set; }
public Dictionary<string, string> headers { get;set;}
public Dictionary<string, string> queryStringParameters {get;set; }
}
public class LambdaProxyResponse
{
public int statusCode { get; set; }
public Dictionary<string, string> headers { get; set; }
public string body { get; set; }
}