Error while running webparts ... Failure to connect to sql server

Last post 05-07-2008 11:40 PM by dodude. 7 replies.

Sort Posts:

  • Error while running webparts ... Failure to connect to sql server

    05-31-2007, 1:31 AM
    • Loading...
    • yennares
    • Joined on 05-21-2007, 11:46 AM
    • Posts 55

    Hi

    I have Sql Server 2000 and VS 2005. I tried to use webparts in vs 2005.

    This is the  Code for default.aspx page.

    <form id="form1" runat="server">

    &nbsp;<asp:ScriptManager ID="ScriptManager1" runat="server" />

    <asp:WebPartManager ID="WebPartManager1" runat="server">

    </asp:WebPartManager>

    <div>

    &nbsp;<table style="width: 49%; height: 44px">

    <tr>

    <td style="width: 100px; text-align: center">

    &nbsp;<asp:WebPartZone ID="WebPartZone1" runat="server">

    <ZoneTemplate>

    <asp:Calendar ID="Calendar1" runat="server" Height="74px" Width="95px"></asp:Calendar>

    </ZoneTemplate>

    </asp:WebPartZone>

    </td>

    <td style="width: 42px; text-align: center">

    &nbsp;<asp:WebPartZone ID="WebPartZone2" runat="server">

    <ZoneTemplate>

    <asp:Calendar ID="Calendar2" runat="server" Height="1px" Width="64px"></asp:Calendar>

    </ZoneTemplate>

    </asp:WebPartZone>

    </td>

    </tr>

    </table>

    </div>

    <br />

    </form>

     

    Whille trying to run, i am getting the following error.

     

    An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    SQLExpress database file auto-creation error:

    The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:

    1. If the applications App_Data directory does not already exist, the web server account must have read and write access to the applications directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.
    2. If the applications App_Data directory already exists, the web server account only requires read and write access to the applications App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the applications App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server accounts credentials are used when creating the new database.
    3. Sql Server Express must be installed on the machine.
    4. The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.
    Stack Trace:

    [SqlException (0x80131904): An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +173
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +199
       System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) +1069
       System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +606
       System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +193
       System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +219
       System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +27
       System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +49
       System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +89
       System.Data.SqlClient.SqlConnection.Open() +160
       System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +67
    
    [HttpException (0x80004005): Unable to connect to SQL Server database.]
       System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +123
       System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +89
       System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +26
       System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +388
    

     Can some one please help me out.

    Yes Please Mark as Answer if this tip solved your problem
  • Re: Error while running webparts ... Failure to connect to sql server

    05-31-2007, 5:33 AM
    Answer

    The Issue:
      The webpartmanager is looking for SQL Express 2005 which, by default, is the personalization provider.  We can work around this but if you are really eager to see your page displayed you can set the Personalization-Enabled="false" in the webpartmanager.  This will render your page but it will also defeat any purpose of using webparts.  For the real solution read on.
    The Solution: (3 simple steps)
    1) Open your visual studio command prompt located in "Start Menu\Programs\Microsoft Visual Studio 2005\Visual Studio Tools\Visual Stuido 2005 Command Prompt" and type in aspnet_regsql.exe.  This will launch a wizard so that you can either create a DB or add tables to an existing database for storing personalization infromation. Click Next, Next, then enter in your DBServer Name. Lets leave the DB as "default" for now, click next, next, finish.  By leaving the db as default the tool will create a database named aspnetdb
    2) Now we have a database so we will need a connection string to access it from our  Personalization Provider in Step 3.  The connection string will go into your web.config and it will be similar to the one show below:
    <connectionStrings>
     <remove name="LocalSqlServer" />
     <add name="DBConn" connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=aspnetdb;Data Source=DBServer" providerName="System.Data.SqlClient" />
    </connectionStrings>

    Note: The "remove" tag is used to inform Visual Studio that we will not be using SQL Express
    3) The final step is to add our own personalization provider in the <system.web> section of the webConfig.  The personalization provider will point to the store we created by using the connection string we provide (Dbconn).
       <personalization  defaultProvider\u003d"AspNetSqlPers\u003cwbr /\>onalizationProvider">\u003cbr /\>        <providers>\u003cbr /\>             <remove name\u003d"AspNetSqlPersonalization\u003cwbr /\>Provider" />\u003cbr /\>             <add name\u003d"AspNetSqlPersonalization\u003cwbr /\>Provider"\u003cbr /\>             type\u003d"System.Web.UI.WebControls\u003cwbr /\>.WebParts.SqlPersonalizationPr\u003cwbr /\>ovider"\u003cbr /\>             connectionStringName\u003d"DBConn"\u003cbr /\>             applicationName\u003d"/" />\u003cbr /\>        </providers>\u003cbr /\>    </personalization>\u003cbr /\></webParts>\u003cbr /\>\u003cbr /\>ALL DONE !!!  Congrats you should be up and running.\u003cbr /\>Give me shout-out if this helped you !!\u003c/div\>",0] ); D(["ce"]); //--> <webParts>
       <personalization  defaultProvider="AspNetSqlPersonalizationProvider">
           <providers>
                <remove name="AspNetSqlPersonalizationProvider" />
                <add name="AspNetSqlPersonalizationProvider"
                type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider"
                connectionStringName="DBConn"
                applicationName="/" />
           </providers>
       </personalization>
    </webParts>

    ALL DONE !!!  Congrats you should be up and running.
    Give me shout-out if this helped you !!
    Regards
    Satheesh Kumar K K
    http://www.quesbank.com
  • Re: Error while running webparts ... Failure to connect to sql server

    05-31-2007, 5:37 AM

    Ignore these lines of code

    <personalization  defaultProvider\u003d"AspNetSqlPers\u003cwbr /\>onalizationProvider">\u003cbr /\>        <providers>\u003cbr /\>             <remove name\u003d"AspNetSqlPersonalization\u003cwbr /\>Provider" />\u003cbr /\>             <add name\u003d"AspNetSqlPersonalization\u003cwbr /\>Provider"\u003cbr /\>             type\u003d"System.Web.UI.WebControls\u003cwbr /\>.WebParts.SqlPersonalizationPr\u003cwbr /\>ovider"\u003cbr /\>             connectionStringName\u003d"DBConn"\u003cbr /\>             applicationName\u003d"/" />\u003cbr /\>        </providers>\u003cbr /\>    </personalization>\u003cbr /\></webParts>\u003cbr /\>\u003cbr /\>ALL DONE !!!  Congrats you should be up and running.\u003cbr /\>Give me shout-out if this helped you !!\u003c/div\>",0] ); D(["ce"]); //--> <webParts>

    Regards
    Satheesh Kumar K K
    http://www.quesbank.com
  • Re: Error while running webparts ... Failure to connect to sql server

    05-31-2007, 7:10 AM
    • Loading...
    • yennares
    • Joined on 05-21-2007, 11:46 AM
    • Posts 55

    I did exactly how you told me to. Now a new error

    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: Unrecognized element 'remove'.

    Source Error:

    Line 22:     <webParts>
    Line 23:       <personalization>
    Line 24:         <remove name="AspNetSqlPersonalizationProvider" />
    Line 25:         <add name="AspNetSqlPersonalizationProvider" type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider" connectionStringName="DBConn" applicationName="/" />
    Line 26:       </personalization

    I am using VS 2005 with AjaxControlToolKit

    Yes Please Mark as Answer if this tip solved your problem
  • Re: Error while running webparts ... Failure to connect to sql server

    05-31-2007, 7:10 AM
    • Loading...
    • yennares
    • Joined on 05-21-2007, 11:46 AM
    • Posts 55

    I did exactly how you told me to. Now a new error

    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: Unrecognized element 'remove'.

    Source Error:

    Line 22:     <webParts>
    Line 23:       <personalization>
    Line 24:         <remove name="AspNetSqlPersonalizationProvider" />
    Line 25:         <add name="AspNetSqlPersonalizationProvider" type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider" connectionStringName="DBConn" applicationName="/" />
    Line 26:       </personalization

    I am using VS 2005 with AjaxControlToolKit

     Any suggestions would be appreciable.

    Thanks in advance

    Yes Please Mark as Answer if this tip solved your problem
  • Re: Error while running webparts ... Failure to connect to sql server

    05-31-2007, 7:24 AM
    • Loading...
    • yennares
    • Joined on 05-21-2007, 11:46 AM
    • Posts 55

    Hi Satheesh Kumar K K

    Its working now. Your code really helped me.

    Thanks

    Yes Please Mark as Answer if this tip solved your problem
  • Re: Error while running webparts ... Failure to connect to sql server

    01-03-2008, 7:47 AM
    • Loading...
    • nitesh_k4u
    • Joined on 01-03-2008, 12:43 PM
    • Posts 1

     

    Hi All I am also using web parts and i also got the similar situation heres my web.config file

    <?xml version="1.0"?><!--

    Note: As an alternative to hand editing this file you can use the

    web admin tool to configure settings for your application. Use

    the Website->Asp.Net Configuration option in Visual Studio.

    A full list of settings and comments can be found in

    machine.config.comments usually located in

    \Windows\Microsoft.Net\Framework\v2.x\Config

    -->

    <
    configuration>

    <appSettings/>

    <connectionStrings>

    <remove name="LocalSqlServer"/>

    <add name="ASPNETDB" connectionString="Data Source=WS4\RAS;Initial Catalog=aspnetdb;Integrated Security=True"/>

    </connectionStrings>

    <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.

    Visual Basic options:

    Set strict="true" to disallow all data type conversions

    where data loss can occur.

    Set explicit="true" to force declaration of all variables.

    -->

     

     

    <
    compilation debug="false" strict="false" explicit="true" />

     

     

    <
    pages>

    <namespaces>

    <clear />

    <add namespace="System" />

    <add namespace="System.Collections" />

    <add namespace="System.Collections.Specialized" />

    <add namespace="System.Configuration" />

    <add namespace="System.Text" />

    <add namespace="System.Text.RegularExpressions" />

    <add namespace="System.Web" />

    <add namespace="System.Web.Caching" />

    <add namespace="System.Web.SessionState" />

    <add namespace="System.Web.Security" />

    <add namespace="System.Web.Profile" />

    <add namespace="System.Web.UI" />

    <add namespace="System.Web.UI.WebControls" />

    <add namespace="System.Web.UI.WebControls.WebParts" />

    <add namespace="System.Web.UI.HtmlControls" />

    </namespaces> </pages>

    <!--

    The <authentication> section enables configuration

    of the security authentication mode used by

    ASP.NET to identify an incoming user.

    -->

    <authentication mode="Forms" >

    <forms name=".ASPXAUTH" protection="All" timeout="30" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/></authentication>

     

    <!--

    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="RemoteOnly" defaultRedirect="GenericErrorPage.htm">

    <error statusCode="403" redirect="NoAccess.htm" />

    <error statusCode="404" redirect="FileNotFound.htm" />

    </customErrors>

    -->

    <webParts>

    <personalization defaultProvider="AspNetSqlPersonalizationProvider">

    <providers>

    <remove name="AspNetSqlPersonalizationProvider"/>

    <add name="AspNetSqlPersonalizationProvider"

    type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider" ConnectionStringName="ASPNETDB" applicationName="/"/>

    </providers>

    </personalization>

    </webParts>

    </system.web>

    </configuration>

     

    Where as the error message i am getting is as follows:-

    Server Error in '/WebParts' Application.

    Configuration Error

    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: The connectionStringName attribute must be specified when registering a personalization provider.

    Source Error:

    Line 78:             <remove name="AspNetSqlPersonalizationProvider"/>
    Line 79:             <add name="AspNetSqlPersonalizationProvider" 
    Line 80:                  type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider" ConnectionStringName="ASPNETDB" applicationName="/"/>
    Line 81: 
    Line 82:           </providers>

    Source File: C:\Documents and Settings\Workstation6\My Documents\Visual Studio 2005\Projects\WebParts\web.config    Line: 80


    Version Information: Microsoft .NET Framework Version:2.0.50727.832; ASP.NET Version:2.0.50727.832

     

    Any help would be apprecieable.

    Thanks

    Nick

  • Re: Error while running webparts ... Failure to connect to sql server

    05-07-2008, 11:40 PM
    • Loading...
    • dodude
    • Joined on 05-07-2008, 11:33 PM
    • Posts 1

    Dear All

    Thang .Net nay Cu Chuoi Qua.

     Because for specify of web part, you just change as below

      <connectionStrings>
        <remove name="LocalSqlServer" />
        <add name="LocalSqlServer" connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=aspnetdb;Data Source=dodude" providerName="System.Data.SqlClient" />
      </connectionStrings>

     regards

    DODUDE
     

     

Page 1 of 1 (8 items)