开发者

Solution for Error 26 - Error Locating Server/Instance Specified?

I have published my website http://www.theyuvaworld.com for my college project but it is showing

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

You can visit website for detailed Error.

My project is C# ASP.NET 4.0 and built in Sql Server 2008 of Visual Studio 2010.

I am using this connection string in every page.

SqlConnect开发者_如何转开发ion con = new SqlConnection("data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true");
SqlCommand cmd = new SqlCommand();

I know I can put it in Web.config but I don't know how to use it in aspx pages for queries?

My Question is : What changes should I do in my Connection String to get my website working.

Other details : I have taken my Web Hosting Plan from http://www.hostingfarms.in and it supports Sql Server 2008.


Try to work around this piece of code .Username and password should be supplied in get connection string if you are using sql authentication

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;";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜