Convert SqlDataSource to SqlConnection

  • Thread starter Thread starter Jeffrey Walton
  • Start date Start date
J

Jeffrey Walton

Hi All,

From [1], I was not able to populate a <asp:Label> solely from the
body using a <asp:SqlDataSource> (it required VB code in the
page_load). This caused me grief since I want a clean solution that
does work one way(all <asp:...>) or another (VB in page_load).

I'm now attempting to perform everything using VB in page_load. I
copied the Data Source property from the SqlDataSource to map it to a
SqlConnection (line breaks added for readability):

Data Source=.\SQLEXPRESS;AttachDbFilename=
|DataDirectory|\Products.mdf;
Integrated Security=True;User Instance=True

To:

Dim connection As New SqlConnection()
connection.ConnectionString =
"Persist Security Info=False;
Integrated Security=SSPI;
database=App_Data\Products.mdf;
server=(local);
Connect Timeout=30"

And:

Dim connection As New SqlConnection()
connection.ConnectionString =
"Persist Security Info=False;
Integrated Security=SSPI;
database=Products.mdf;
server=(local);
Connect Timeout=30"

When I call Open(), I receive the following exception:

A network-related or instance-specific error occurred while
establishing
a connection to SQL Server. The server was not found or was not
accessible.
Verify that the instance name is correct and that SQL Server is
configured
to allow remote connections. (provider: Named Pipes Provider,
error: 40 -
Could not open a connection to SQL Server)

Obviously, the local host does exist. Tthe SqlDataSource works so the
database does exist. Any help would be appreciated.

Jeff

[1] http://groups.google.com/group/micr....aspnet/browse_thread/thread/8cd2a368f9433c4b
 
Disregard. I attempted to use the SqlConnection as documented on
MSDN. I found I can use the SqlDataSource property as the connection
string.
 
Back
Top