簡體   English   中英

錯誤26的解決方案-指定錯誤的服務器/實例定位?

[英]Solution for Error 26 - Error Locating Server/Instance Specified?

我已經為我的大學項目發布了我的網站http://www.theyuvaworld.com ,但該網站正在顯示

Error 26 - Error Locating Server/Instance Specified. Other things are working properly.

您可以訪問網站以獲取詳細的錯誤信息。

我的項目是C# ASP.NET 4.0並在Visual Studio 2010的Sql Server 2008中構建。

我在每個頁面中都使用此連接字符串。

SqlConnection con = new SqlConnection("data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true");
SqlCommand cmd = new SqlCommand();

我知道我可以將其放在Web.config但是我不知道如何在aspx頁面中使用它進行查詢?

我的問題是:我應該在我的連接字符串中進行哪些更改才能使我的網站正常工作。

其他詳細信息:我從http://www.hostingfarms.in獲得了Web托管計划,它支持Sql Server 2008。

嘗試解決這段代碼。如果使用sql身份驗證,則應在get連接字符串中提供用戶名和密碼。

private static void OpenSqlConnection()
{
    string connectionString = GetConnectionString();

    using (SqlConnection connection = new SqlConnection())
    {
        connection.ConnectionString = connectionString;

        connection.Open();

        Console.WriteLine("State: {0}", connection.State);
        Console.WriteLine("ConnectionString: {0}",
            connection.ConnectionString);
    }
}

static private string GetConnectionString()
{
    // To avoid storing the connection string in your code, 
    // you can retrieve it from a configuration file.
    return "Data Source=MSSQL1;Initial Catalog=AdventureWorks;"
        + "Integrated Security=true;";
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM