PC Review


Reply
Thread Tools Rate Thread

Convert SqlDataSource to SqlConnection

 
 
Jeffrey Walton
Guest
Posts: n/a
 
      30th Nov 2009
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/micro...d2a368f9433c4b
 
Reply With Quote
 
 
 
 
Jeffrey Walton
Guest
Posts: n/a
 
      30th Nov 2009
Disregard. I attempted to use the SqlConnection as documented on
MSDN. I found I can use the SqlDataSource property as the connection
string.

On Nov 30, 1:56*am, Jeffrey Walton <noloa...@gmail.com> wrote:
> 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/microsoft.public.dotnet.framework.aspn....


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DAL Question: SqlConnection vs SqlDataSource John Kotuby Microsoft ASP .NET 9 31st Jan 2008 05:49 PM
are System.Data.SqlClient.SqlConnection thread safe? can many threads share a System.Data.SqlClient.SqlConnection instance without any synchronization? Daniel Microsoft Dot NET Framework 6 24th Mar 2006 01:01 AM
are System.Data.SqlClient.SqlConnection thread safe? can many threads share a System.Data.SqlClient.SqlConnection instance without any synchronization? Daniel Microsoft Dot NET 2 22nd Mar 2006 07:01 PM
are System.Data.SqlClient.SqlConnection thread safe? can many threads share a System.Data.SqlClient.SqlConnection instance without any synchronization? Daniel Microsoft C# .NET 1 22nd Mar 2006 06:34 AM
the difference between SqlConnection.IDisposable.Dispose() and SqlConnection.Dispose() jinfeng_Wang@msn.com Microsoft Dot NET 1 18th Jan 2006 08:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:15 AM.