停止数据库进程 [英] Stopping a database process

查看:173
本文介绍了停止数据库进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个数据库(使用visual studio 2013提供的数据库),我需要杀死数据库进程,以便我可以在另一个按钮上使用它。当我尝试按下此按钮(此按钮直接访问数据库)时的当前错误如下:



Hi, so I have a database (using the database provided by visual studio 2013) and I need to kill the database process so I can use it on another "button". The current error when i try to press this button (this button directly accesses the database) is below:

Unable to open the physical file "C:\Users\Slay3r\Documents\Visual Studio 2013\Projects\Project Thesis\Project Thesis\App_Data\ProjectThesis.mdf". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)".
An attempt to attach an auto-named database for file C:\Users\Slay3r\Documents\Visual Studio 2013\Projects\Project Thesis\Project Thesis\App_Data\ProjectThesis.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.





我在aspx上有以下代码





I have the following code on an aspx

public void SaveToDatabase()
{
    string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ProjectThesis.mdf;Integrated Security=True;User Instance=True";
    using (SqlConnection conn = new SqlConnection(connectionString))
    {
        SqlCommand CmdSql = new SqlCommand("INSERT INTO BookDetails (ISBN,BookTitle,Price,WebLink,WebSource) VALUES (@ISBN,@BookTitle,@Price,@WebLink, @WebSource)", conn);
        conn.Open();
        CmdSql.Parameters.AddWithValue("@ISBN", ISBN);
        CmdSql.Parameters.AddWithValue("@BookTitle", Title);
        CmdSql.Parameters.AddWithValue("@Price", Prices.Price);
        CmdSql.Parameters.AddWithValue("@WebLink", Url);
        CmdSql.Parameters.AddWithValue("@WebSource", Source);
        CmdSql.ExecuteNonQuery();
        conn.Close();
    }
}









public DataSet GetDetails()

{



DataTable dt = new DataTable();



dt.Columns.Add(ISBN);

dt.Columns.Add(Book Title);

dt.Columns.Add(价格,typeof(double));

dt.Columns.Add(Web Link);

dt.Columns.Add(Web Source); < br $>


foreach(收藏中的书详细信息)

{

DataRow dr = dt.NewRow();

dr [0] = detail.ISBN;

dr [1] = detail.Title;

dr [2] = detail.Prices.Price ;

dr [3] = detail.Url;

dr [4] = detail.Source;

dt.Rows .Add(dr);

}



DataSet ds = new DataSet();

ds.Tables .Add(dt);

返回ds;

}



在另一个aspx页面上我有一个gridview具有当前代码:





and

public DataSet GetDetails()
{

DataTable dt = new DataTable();

dt.Columns.Add("ISBN");
dt.Columns.Add("Book Title");
dt.Columns.Add("Price", typeof(double));
dt.Columns.Add("Web Link");
dt.Columns.Add("Web Source");

foreach (BookDetails detail in Collection)
{
DataRow dr = dt.NewRow();
dr[0] = detail.ISBN;
dr[1] = detail.Title;
dr[2] = detail.Prices.Price;
dr[3] = detail.Url;
dr[4] = detail.Source;
dt.Rows.Add(dr);
}

DataSet ds = new DataSet();
ds.Tables.Add(dt);
return ds;
}

On another aspx page i have a gridview that has the current code:

<h2 class="title"><a>Book Database Entry</a></h2>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Height="100px" Width="500px">
    <Columns>
        <asp:BoundField DataField="DateCreated" HeaderText="DateCreated" SortExpression="DateCreated" />
        <asp:BoundField DataField="ISBN" HeaderText="ISBN" SortExpression="ISBN" />
        <asp:BoundField DataField="BookTitle" HeaderText="BookTitle" SortExpression="BookTitle" />
        <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
          <asp:TemplateField HeaderText="WebLink">
               <ItemTemplate>
                   <asp:HyperLink ID="HyperLink1" Text='<%# Eval("WebLink")%>' runat="server" NavigateUrl='<%# Eval("WebLink") %>'></asp:HyperLink>
               </ItemTemplate>
           </asp:TemplateField>
        <asp:BoundField DataField="WebSource" HeaderText="WebSource" SortExpression="WebSource" />
    </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" SelectCommand="SELECT [BookTitle], [Price], [WebLink], [WebSource], [DateCreated], [ISBN] FROM [BookDetails] ORDER BY [DateCreated] DESC"></asp:SqlDataSource>





为了纠正错误我需要杀死当前的数据库进程吗?我该怎么做?



谢谢!



In order to correct the error I need to kill the current database process right? how do i do that?

Thanks!

推荐答案

ConnectionStrings:ConnectionString2 %> SelectCommand = SELECT [BookTitle],[Price],[WebLink],[WebSource],[DateCreated],[ISBN] FROM [BookDetails] ORDER BY [DateCreated] DESC > < / asp:SqlDataSource >
ConnectionStrings:ConnectionString2 %>" SelectCommand="SELECT [BookTitle], [Price], [WebLink], [WebSource], [DateCreated], [ISBN] FROM [BookDetails] ORDER BY [DateCreated] DESC"></asp:SqlDataSource>





In为了纠正我需要杀死当前数据库进程的错误吗?我该怎么做?



谢谢!



In order to correct the error I need to kill the current database process right? how do i do that?

Thanks!


这篇关于停止数据库进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆