2016-06-22 84 views
0

我搜索了很多關於這個計算器錯誤,而是來自我的錯誤遠遠受到這些問題......asp.net - 的SQLException是由用戶代碼未處理的

我與「TUTS +」教程編程CMS而我每次我試圖解決這個問題得到這個代碼... 錯誤:

Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) I tried for restart sql services and turn off firewall and... but!... and the code :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text.RegularExpressions; 
using System.Web; 
using WebMatrix.Data; 


/// <summary> 
/// Summary description for PostHandler 
/// </summary> 
public class PostHandler : IHttpHandler 
{ 
    public PostHandler() 
    { 
     // 
     // TODO: Add constructor logic here 
     // 
    } 

    public bool IsReusable 
    { 
     get { return false; } 
    } 

    public void ProcessRequest(HttpContext context) 
    { 
     var title = context.Request.Form["postTitle"]; 
     var content = context.Request.Form["postContent"]; 
     var slug = CreateSlug(title); 


     using (var db = Database.Open("DefaultConnection")) 

     { 

      var sql = "SELECT * FROM Posts WHERE Slug = @0"; 

      var result = db.QuerySingle(sql, slug); 




      if (result != null) { 

       throw new HttpException(409, "SLUG IS ALREADY IN USE!"); 

      } 

      sql = "INSERT INTO Posts (Title, Content, AuthorId, Slug" + 
        "VALUES (@0, @1, @2, @3)"; 
      db.Execute(sql, title, content, 1, slug); 
     } 
    } 


    private static string CreateSlug(String title) 
    { 
     title = title.ToLowerInvariant().Replace(" ", "-"); 
     title = Regex.Replace(title, @"[^0-9a-z-]", string.Empty); 

     return title; 
    } 
} 

我上線這個錯誤:

var result = db.QuerySingle(sql, slug);

+1

此錯誤表示您的連接字符串錯誤。它存儲在web.config中。有關如何放置連接字符串,請參閱https://www.connectionstrings.com/sql-server/。沒有通用的方法來排除故障連接字符串 – MatthewMartin

回答

-1

轉到控制面板/搜索服務找到SQL Server(XXX)服務,並檢查它是否正在運行。如果它沒有運行,那麼啓動它並嘗試再次在SSMS中登錄。

閱讀全文Here帶圖片插圖

+0

所有這些都在運行好友... – Mohammadreza

相關問題