如果输入01-01-2015它应该改为2015-01-01.
如果输入2015-01-01它应该改为01-01-2015.
我使用SimpleDateFormat但没有得到正确的输出:
//Class to change date dd-MM-yyyy to yyyy-MM-dd and vice versa
public class ChangeDate {
static SimpleDateFormat formatY = new SimpleDateFormat("yyyy-MM-dd");
static SimpleDateFormat formatD = new SimpleDateFormat("dd-MM-yyyy");
//This function change dd-MM-yyyy to yyyy-MM-dd
public static String changeDtoY(String date) {
try {
return formatY.format(formatD.parse(date));
}
catch(Exception e) {
return null;
}
}
//This function change yyyy-MM-dd to dd-MM-yyyy
public static String changeYtoD(String date) {
try {
return formatD.format(formatY.parse(date));
} …Run Code Online (Sandbox Code Playgroud) 我无法使用C#webapi将大量数据插入Azure SQL服务器数据库
考虑
我想在SQL中插入60K>数据。在我的本地sql服务器中没有问题,但是在Azure SQL中,它的连接超时
我的方法:(所有人都在本地sql服务器中工作,但不在Azure sql服务器中工作)
1)使用EF对其插入记录进行一次尝试(10000次约10分钟,大多数情况下超时)
2)尝试将批量插入扩展与EF一起使用3)尝试在SqlBulkCopy中
4)尝试增加连接字符串中的连接超时
5)尝试在Dbcontext中增加命令超时。
异常StackTrace
Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 …Run Code Online (Sandbox Code Playgroud) 我正在使用 webapi MVC 模板 使用默认的 XmlSerializer 我得到以下输出
OUTPUT:
<ClassName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Child1>String</Child>
<Child2 xsi:nil=true/>
</ClassName>
DTO class
[XmlRoot("ClassName")]
[DataContract]
public class ClassName
{
[DataMember]
[XmlElement("Child1")]
public string Child1{ get; set; }
[DataMember]
[XmlElement("Child2",IsNullable =true)]
public string Child2{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我设法通过覆盖默认的 xmlformatter 来删除根节点命名空间
//Code to remove root node namespace
using (XmlWriter xw = XmlWriter.Create(streamWriter, settings))
{
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
serializer.Serialize(xw, value, ns);
}
Run Code Online (Sandbox Code Playgroud)
但是现在根节点中的命名空间被删除,但子节点仍然具有命名空间
Current Output:
<ClassName>
<Child1>String</Child>
<Child2 xsi:nil=true p2:nil="true" xmlns:p2="http://www.w3.org/2001/XMLSchema-instance"/>
</ClassName>
Expected output: …Run Code Online (Sandbox Code Playgroud)