user595234
user595234

Reputation: 6259

Visual Studio, Asp.net connection string

In the Visual Studio, it will generate datasource like this :

<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString1 %>" 
        SelectCommand="SELECT top 10 * FROM [Address]">
    </asp:SqlDataSource>

when run it, it will say 'invalid object'. then I found it out, it should be

[AdventureWorks].[Person].[Address]

The connection string is

 <connectionStrings>
        <add name="AdventureWorksConnectionString1" connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>

Then how to config in VS to use this format ?

Upvotes: 0

Views: 238

Answers (1)

Oded
Oded

Reputation: 499302

The default schema for the logged in database user is probably [dbo], not [Person]. You need to qualify the schema name in such a case.

Your select command should be:

SELECT top 10 * FROM [Person].[Address]

Upvotes: 2

Related Questions