How to: Associate a Query with a Connection in a Project
If a query was created without a connection, or if a query is moved from one project to another it will not be associated with a connection in the current project.
To associate a query with a connection in a project
If the query is open in query editor, right-click a blank area of query editor, point to Connection, and then click Connect. If the query is not open, double-click the query in Solution Explorer to connect the query.
In the Connect to Database Engine dialog box, provide the connection information. If the connection information matches an existing connection, the query will be associated with that connection.