Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unrecognized connection string

Status
Not open for further replies.

CoolMama

Programmer
Jan 19, 2006
50
0
0
US
I've set up an ASP.NET page reading from a SQL Server Express database on my computer. When I migrate the page to a web server which has the same SQL Server Express setup and database file path, I get the error below. Everything looks fine. I even changed the [local] server path (.\SQLEXPRESS) to an absolute path (EDSERVER\SQLEXPRESS) to see if it would help.

The web.cong files reads
Code:
<connectionStrings>
    <add name="RISBpolicies" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\policiesSQL.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
        providerName="System.Data.SqlClient" />
</connectionStrings>

The ASP.NET page reads
Code:
<asp:SqlDataSource ID="PFFpolicies" runat="server" ConnectionString="<%$ ConnectionStrings:RISBpolicies %>"
            SelectCommand="SELECT * FROM [PFFPolicies] ORDER BY [PageNumber]" ProviderName="<%$ ConnectionStrings:RISBpolicies.ProviderName %>"></asp:SqlDataSource>

The error code reads
Code:
Server Error in '/' 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: Unrecognized configuration section 'connectionStrings'

Source Error: 

Line 1:  <configuration>
Line 2:  <connectionStrings>
Line 3:      <add name="RISBpolicies" connectionString="Data Source=EDSERVER\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\policiesSQL.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
Line 4:          providerName="System.Data.SqlClient" />

[red]Source File: D:\web\RISB_SITE\web.config    Line: 2[/red] 

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

Although now that I look at it...I was told .NET 2.0 was loaded on the web server. But the version info on the error says
Code:
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

Could that be it? Or is it something else?

Dawn
 
Certainly, you need to make sure that IIS is setup to use the correct version of the framework.

Also, you can open the SQL Server on the server and make sure that you have the correct Instance name.
 
OK, now the Framework has been updated. But there is a new message that I don't understand. Using this connection string, I get the following error. I know the database file is there under that path. I don't believe a password is needed to access it. SQL Server Express is set up as "Local System". So what is this referring to?

Code:
<connectionStrings>
    <add name="RISBpolicies" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\policiesSQL.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
        providerName="System.Data.SqlClient" />
</connectionStrings>

[red]ERROR[/red]
Code:
Server Error in '/' Application. 

An attempt to attach an auto-named database for file C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\policiesSQL.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. 
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. 

Exception Details: System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\policiesSQL.mdf failed. [red]A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.[/red]

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 

[SqlException (0x80131904): An attempt to attach an auto-named database for file C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\policiesSQL.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734995
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838
   System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +33
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +628
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +170
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +359
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +496
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
   System.Data.SqlClient.SqlConnection.Open() +111
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +83
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1770
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +41
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Control.PreRenderRecursiveInternal() +161
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360


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

Dawn
 
I haven't done it like that with the AttachDbFileName. Try this as a connection string...

Code:
<add name="ConnString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=policiesSQL;Integrated Security=True/>

or "Integrated Security=SSPI"

See if that works.
 
I tried both suggestions...together and separately...and below was the better of the error messages. But I don't know what it means either.

Code:
<connectionStrings>
    <add name="ConnString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=policiesSQL;Integrated Security=SSPI />
</connectionStrings>

ERROR
Code:
Parser Error Message: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 4, position 1.

Source Error: 


Line 2:  <connectionStrings>
Line 3:      <add name="ConnString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=policiesSQL;Integrated Security=SSPI />
[red]Line 4:  </connectionStrings>[/red]
Line 5:      <system.web>
Line 6:  
 

Source File: D:\web\RISB_SITE\web.config    Line: 4

Dawn
 
Sorry, I made a syntax error. You need to add another quotation mark to the end of the string (I forgot to close it off).

Also, you might want to add the providerName="System.Data.SqlClient" part (not exactly sure).

J

Code:
<add name="ConnString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=policiesSQL;Integrated Security=SSPI[b]"[/b] />
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top