Click here to Skip to main content
14,431,049 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have launched my website over Internet but database pages are not opened. My website is made in visual studio 2008 and inbuilt database using SQL sever 2005 but while accessing its database pages error of instance specified with code 26 occurs
My class.cs file code:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
/// Summary description for Class1
///
public class Class1
{
SqlConnection con;
SqlCommand com;
public SqlDataReader dr;
public SqlDataAdapter da;
public Class1()
{
//
// TODO: Add constructor logic here
//
}
public void ConnectClass1()
{
con = new SqlConnection();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=" + System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\Gurukuldata.mdf")+";Integrated Security=True;User Instance=True";
con.Open();
}
public void ExecuteNonSelect(string query)
{
com = new SqlCommand();
com.CommandText = query;
com.Connection = con;
com.ExecuteNonQuery();
}
public void ExecuteSelect(string query)
{
com = new SqlCommand();
com.CommandText = query;
com.Connection = con;
dr = com.ExecuteReader();
}
public DataSet ExecuteSelect1(string query)
{
da = new SqlDataAdapter(query,con);
DataSet ds = new DataSet();
da.Fill(ds);
return (ds);
}
}

And web.config code :
<?xml version="1.0" encoding="UTF-8"?>
<!--
Please refer to machine.config.comments for a description and
the default values of each configuration section.

For a full documentation of the schema please refer to
http://go.microsoft.com/fwlink/?LinkId=42127

To improve performance, machine.config should contain only those
settings that differ from their defaults.
-->
<configuration>
<configsections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">




<appSettings />
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true" defaultLanguage="c#">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<!-- <add assembly="Microsoft.Office.Interop.Outlook, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C" />
-->


<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<!--
The <customerrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
-->
<customErrors mode="Off" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />

<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />


<httphandlers>
<remove verb="*" path="*.asmx" />
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" />

<httpmodules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />


<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5" />
<providerOption name="WarnAsError" value="false" />

<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5" />
<providerOption name="OptionInfer" value="true" />
<providerOption name="WarnAsError" value="false" />



<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webserver>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<remove name="ScriptModule" />
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

<handlers>
<remove name="WebServiceHandlerFactory-Integrated" />
<remove name="ScriptHandlerFactory" />
<remove name="ScriptHandlerFactoryAppServices" />
<remove name="ScriptResource" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />


<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentassembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />

<dependentassembly>
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" />



<connectionstrings>

<add name="ConnectionString" connectionString="Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Gurukuldata.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
<!-- <add name="LocalSqlServer" connectionString="Data Source=(LocalDB\V11.0;Initial Catalog=Gurukuldata; Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Gurukuldata.mdf" providerName="System.Data.SqlClient"/>
<add name="SQLEXPRESS" connectionString="Data Source=SQLEXPRESS;Initial Catalog=GurukuldataEXPRESS; Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Gurukuldata.mdf" providerName="System.Data.SqlClient"/>
-->



What I have tried:

Plz help I have tried changing Connection string but it doesn't work
Posted
Updated 14-Dec-16 4:57am
Comments
F-ES Sitecore 14-Dec-16 9:47am
   
First thing is to post the text of the errors, but ultimately you need to ensure the connection string is correct for the environment you have published to, ie there is a database server of the correct type and right instance name as defined in the connection.
[no name] 14-Dec-16 9:49am
   
Maybe your website hosting provider didn't name their SQL Server instance "SQLEXPRESS"

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=" + System.Web.HttpContext.Current.Server.MapPath("~\\App_Data\\Gurukuldata.mdf")+";Integrated Security=True;User Instance=True";

Never hardcode connection strings: in this case they should be a part of the web.config file.
This may help you to keep it organised: Supporting Development and Release web.config in ASP.NET[^]
But you need to look to your hosting service for the details: the SQL server instance will not be SQLEPRESS, and it's very, very unlikely they will use Integrated Security instead of a user name and password combination - but only they can give you the info you need.
And it's very, very, unlikely that Attach will work in production either: that's a special Development mode that only exists in Express editions, which your hosting service is very unlikely to use. You need to create the DB in the SQL server instance, not attach an existing MDF file.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100