Convert SqlDataSource to SqlConnection

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
 
J

Jeffrey Walton

Disregard. I attempted to use the SqlConnection as documented on
MSDN. I found I can use the SqlDataSource property as the connection
string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top