我想从命令行导出和导入MySQL数据库的.sql文件.
是否有任何命令在MySQL中导出.sql文件?那我该如何导入呢?
执行导入时,可能存在启用/禁用外键检查或仅导出表结构等约束.
我们可以设置这些选项用mysqldump
?
我的网站上有很多用户(每天20000-60000),这是一个移动文件的下载站点.我可以远程访问我的服务器(Windows Server 2008-R2).
我之前收到"服务器不可用"错误,但现在看到连接超时错误.
我不熟悉这个 - 它为什么会发生,我该如何解决?
完整错误如下:
'/'应用程序中的服务器错误.超时已过期.操作完成之前经过的超时时间或服务器没有响应.该语句已终止.描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息:System.Data.SqlClient.SqlException:超时已过期.操作完成之前经过的超时时间或服务器没有响应.该语句已终止.
来源错误:
在执行当前Web请求期间生成了未处理的异常.可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息.
堆栈跟踪:
[SqlException(0x80131904):超时已过期.操作完成之前经过的超时时间或服务器没有响应.语句已终止.]
System.Data.SqlClient.SqlConnection.OnError(SqlException异常,Boolean breakConnection
)+404
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()+ 412 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior ,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)+1363
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,String resetOptionsString)+6387741
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async)+6389442
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method,DbAsyncResult result)+538
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName,Boolean sendToPipe)+689
System.Data.SqlClient.SqlCommand.Execu teNonQuery()+ 327
NovinMedia.Data.DbObject.RunProcedure(String storedProcName,IDataParameter []参数,Int32和rowsAffected)+209
DataLayer.OnlineUsers.Update_SessionEnd_And_Online(Object Session_End,Boolean Online)+440
NiceFileExplorer.Global.Application_Start(Object sender,EventArgs e)+163[HttpException(0x80004005):超时已过期.操作完成之前经过的超时时间或服务器没有响应.该语句已被终止.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context,HttpApplication app)+4052053
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext context,MethodInfo [] handlers)+191
System.Web.HttpApplication. InitSpecial(HttpApplicationState状态,MethodInfo的[]处理程序,IntPtr的appContext,HttpContext的上下文)352
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr的appContext,HttpContext的上下文)407
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr的appContext)375[HttpException(0x80004005):超时已过期.操作完成之前经过的超时时间或服务器没有响应.该语句已被终止.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context)+11686928 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)+141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext …
SqlConnection在事务中"登记"是什么意思?它只是意味着我在连接上执行的命令将参与事务吗?
如果是这样,在什么情况下SqlConnection会自动登记在环境TransactionScope事务中?
查看代码注释中的问题.我对每个问题的答案的猜测都在括号中的每个问题之后.
using (TransactionScope scope = new TransactionScope())
using (SqlConnection conn = ConnectToDB())
{
// Q1: Is connection automatically enlisted in transaction? (Yes?)
//
// Q2: If I open (and run commands on) a second connection now,
// with an identical connection string,
// what, if any, is the relationship of this second connection to the first?
//
// Q3: Will this second connection's automatic enlistment
// in the current transaction scope cause the transaction to …
Run Code Online (Sandbox Code Playgroud) 我有一个MS SQL Server 2005数据库.在一些过程中,我将表参数作为nvarchar(以逗号分隔)传递给存储过程,并在内部划分为单个值.我将它添加到SQL命令参数列表中,如下所示:
cmd.Parameters.Add("@Logins", SqlDbType.NVarchar).Value = "jim18,jenny1975,cosmo";
Run Code Online (Sandbox Code Playgroud)
我必须将数据库迁移到SQL Server 2008.我知道有表值参数,我知道如何在存储过程中使用它们.但我不知道如何将一个传递给SQL命令中的参数列表.有谁知道Parameters.Add
程序的正确语法?或者是否有另一种传递此参数的方法?
c# sql-server stored-procedures sqlcommand table-valued-parameters
根据我在这里关于Disposable对象的另一个问题,我们应该在using块结束之前调用Close()吗?
using (SqlConnection connection = new SqlConnection())
using (SqlCommand command = new SqlCommand())
{
command.CommandText = "INSERT INTO YourMom (Amount) VALUES (1)";
command.CommandType = System.Data.CommandType.Text;
connection.Open();
command.ExecuteNonQuery();
// Is this call necessary?
connection.Close();
}
Run Code Online (Sandbox Code Playgroud) .NET SqlCommand.CommandTimeout
和SqlConnection.ConnectionTimeout
.NET 之间有什么区别吗?
将参数传递给SQLCommand的最佳方法是什么?你可以做:
cmd.Parameters.Add("@Name", SqlDbType.VarChar, 20).Value = "Bob";
Run Code Online (Sandbox Code Playgroud)
要么
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = "Bob";
Run Code Online (Sandbox Code Playgroud)
要么
cmd.Parameters.Add("@Name").Value = "Bob";
Run Code Online (Sandbox Code Playgroud)
看起来第一个可能在某种程度上"更好",无论是性能方面还是错误检查方式.但我想更清楚地知道.
我可以有效地使用这种方法吗?
using(SqlCommand cmd = new SqlCommand("GetSomething", new SqlConnection(Config.ConnectionString))
{
cmd.Connection.Open();
// set up parameters and CommandType to StoredProcedure etc. etc.
cmd.ExecuteNonQuery();
}
Run Code Online (Sandbox Code Playgroud)
我担心的是:SqlCommand的Dispose方法(在退出using块时调用)是否会关闭底层的SqlConnection对象?
我有一小段代码,它最初反复创建了一个SqlDataAdapter对象.
尝试简化我的调用,我用SqlCommand替换了SqlDataAdapter,并将SqlConnection移到了循环之外.
现在,每当我尝试编辑返回到我的DataTable的数据行时,我都会抛出之前未抛出的ReadOnlyException.
注意:我有一个自定义函数,可根据其ID检索员工的全名.为简单起见,我在下面的示例代码中使用了"John Doe"来证明我的观点.
ExampleQueryOld与SqlDataAdapter一起使用 ; 每当我尝试写入DataRow的元素时,ExampleQueryNew都会因ReadOnlyException 而失败:
这有效,没有问题:
public static DataTable ExampleQueryOld(string targetItem, string[] sqlQueryStrings) {
DataTable bigTable = new DataTable();
for (int i = 0; i < sqlQueryStrings.Length; i++) {
string sqlText = sqlQueryStrings[i];
DataTable data = new DataTable(targetItem);
using (SqlDataAdapter da = new SqlDataAdapter(sqlText, Global.Data.Connection)) {
try {
da.Fill(data);
} catch (Exception err) {
Global.LogError(_CODEFILE, …
Run Code Online (Sandbox Code Playgroud) sqlcommand ×10
c# ×6
.net ×3
ado.net ×2
asp.net ×2
sql-server ×2
command-line ×1
datatable ×1
dispose ×1
mysql ×1
sql ×1
timeout ×1
using ×1