is it possible in the ConnectionStrin g of an asp:SqlDataSour ce construction
to refer to a variable i define at the top of my ASPX script and initialize,
for example, during Page_Init()?
(the only examples i have seen use hard-coded references to connection
strings defined in machine.config, e.g.
<asp:SqlDataSou rce ID="SqlDataSour ce2" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs: connStrInMachCo nfig %>"
not knowing quite how the
<%$ ... %>
magic is definied i'm at a loss to figure it out on my own.
)
i'd be grateful for pointers.
Tim Hanson 11 4879
you cannot use <%= %with server side controls, and the <%# %is for
binding. in OnPreInit set the value rom the code behind.
-- bruce (sqlwork.com)
"tbh" <fe****@newsgro ups.nospamwrote in message
news:eI******** ******@TK2MSFTN GP02.phx.gbl...
is it possible in the ConnectionStrin g of an asp:SqlDataSour ce
construction to refer to a variable i define at the top of my ASPX script
and initialize, for example, during Page_Init()?
(the only examples i have seen use hard-coded references to connection
strings defined in machine.config, e.g.
<asp:SqlDataSou rce ID="SqlDataSour ce2" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs: connStrInMachCo nfig %>"
not knowing quite how the
<%$ ... %>
magic is definied i'm at a loss to figure it out on my own.
)
i'd be grateful for pointers.
Tim Hanson
thanks, Bruce.
sounds like you know some magic i need. do you have a reference (book, URL)
that explains the rules for (what i take to be 3 forms of magic)
<%$ ... %>
<%= %>
<%# %>
?
cheers,
Tim
you cannot use <%= %with server side controls, and the <%# %is for
binding. in OnPreInit set the value rom the code behind.
-- bruce (sqlwork.com)
Hi Tim,
Why not just assign the connection string in code?
Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
sqldatasource1. ConnectionStrin g = _
System.Web.Conf iguration.WebCo nfigurationMana ger. _
ConnectionStrin gs("authorsConn ectionString"). _
ConnectionStrin g
End Sub
Ken
Microsoft MVP [ASP.NET]
"tbh" <fe****@newsgro ups.nospamwrote in message
news:eI******** ******@TK2MSFTN GP02.phx.gbl...
is it possible in the ConnectionStrin g of an asp:SqlDataSour ce
construction to refer to a variable i define at the top of my ASPX script
and initialize, for example, during Page_Init()?
(the only examples i have seen use hard-coded references to connection
strings defined in machine.config, e.g.
<asp:SqlDataSou rce ID="SqlDataSour ce2" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs: connStrInMachCo nfig %>"
not knowing quite how the
<%$ ... %>
magic is definied i'm at a loss to figure it out on my own.
)
i'd be grateful for pointers.
Tim Hanson
thanks, Ken, that's excactly what i needed -- translated to C# and I used
Page_Init().
in retrospect it seems like a dumb question, but i sometimes have trouble
remembering how the declarative bits relate to the procedural bits, even
though i shouldn't.
cheers,
Tim
In Asp.net the WEB.CONFIG file has been created for the purpose of accessing
GLOBAL Application variables. This is where you should store your connection
string. If your using the free and Brilliant Visual Web Developer, you
should see that a web.config file is created for you when you create a new
website. If your using an existing website without a WEB.CONFIG file you can
create one in VWD or VS.NET by right clicking on your project and clicking
ADD NEW ITEM.
Once you've done this you can add a new connection string in this XML based
document.
Heres the code for the KEY valued pair connection variables:
<appSettings>
<add key="MyConnStri ng"
value="server=l ocalhost;databa se=Northwind;ui d=sa;password=s ecret;" />
</appSettings>
Now in any subsequent classes or ASPX pages that you create simply call the
connectionstrin g as:
Dim cn As New
SqlConnection(C onfigurationSet tings.AppSettin gs("MyConnStrin g").ToString ())
or in ASP.NET 2.0
Dim cn As New
SqlConnection(C onfigurationMan ager.Connection Strings("Connec tionString").Co nnectionString. ToString())
Hope this helps!
Damian
MCP
hmm, the plot thickens. this works initially, but on it fails as attached on
__doPostBack().
any ideas? i've tried adding a couple of additional event handlers (that
call my initialization code), but no luck so far. e.g.
protected override void OnPreRender(Eve ntArgs e) {
initConnectionS trings();
base.OnPreRende r(e);
}
cheers,
Tim
Stack Trace:
[InvalidOperatio nException: The ConnectionStrin g property has not been
initialized.]
System.Data.Sql Client.SqlConne ction.Permissio nDemand() +852019
System.Data.Sql Client.SqlConne ctionFactory.Pe rmissionDemand( DbConnection
outerConnection ) +22
System.Data.Pro viderBase.DbCon nectionClosed.O penConnection(D bConnection
outerConnection , DbConnectionFac tory connectionFacto ry) +105
System.Data.Sql Client.SqlConne ction.Open() +111
System.Data.Com mon.DbDataAdapt er.FillInternal (DataSet dataset,
DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String
srcTable, IDbCommand command, CommandBehavior behavior) +121
System.Data.Com mon.DbDataAdapt er.Fill(DataSet dataSet, Int32 startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior) +137
System.Data.Com mon.DbDataAdapt er.Fill(DataSet dataSet, String srcTable)
+83
System.Web.UI.W ebControls.SqlD ataSourceView.E xecuteSelect(Da taSourceSelectA rguments
arguments) +1770
System.Web.UI.D ataSourceView.S elect(DataSourc eSelectArgument s arguments,
DataSourceViewS electCallback callback) +17
System.Web.UI.W ebControls.Data BoundControl.Pe rformSelect() +149
System.Web.UI.W ebControls.Base DataBoundContro l.DataBind() +70
System.Web.UI.W ebControls.Grid View.DataBind() +4
System.Web.UI.W ebControls.Base DataBoundContro l.EnsureDataBou nd() +82
System.Web.UI.W ebControls.Grid View.OnPreRende r(EventArgs e) +24
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +77
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +161
System.Web.UI.C ontrol.PreRende rRecursiveInter nal() +161
System.Web.UI.P age.ProcessRequ estMain(Boolean
includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +1360
Hello Tim,
Have you try to set the connction string in SqlDataSource's Init event or
load event?
Sincerely,
Luke Zhang
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
thanks, Luke, seems like a great idea. once again i didn't know there was
such a thing. haven't learned to think enough in DotNet yet, i fear.
what are my options here? i see from an MSDN document that i can name the
Init Event Handler. but wouldn't it be better to know what the default
handler is (so i can call it before or after my code)?
Have you try to set the connction string in SqlDataSource's Init event or
load event?
Hello,
What is the "default handler" here? The SqlDataSource's event handler? You
may refer following page to see all of its events we can use: http://msdn2.microsoft.com/en-us/library/5b6ksy3z.aspx
Sincerely,
Luke Zhang
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike Kelly |
last post by:
I've chosen to implement the "optimistic concurrency" model in my
application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to
my main tables. I read the value of the column in my select, remember it, and
then use it in the update. It works just fine when I have full control of the
whole process.
I want to do the same for my GridView/SqlDataSource combinations. I
typically select from a view and update the corresponding...
|
by: Arne Garvander |
last post by:
How do I set parameters from code for a SqlDataSource?
--
Arne Garvander
(I program VB.Net for fun and C# to get paid.)
|
by: saturnius |
last post by:
Hello, I have to save the data from a gridview as XML file. The code is
shown below. Is there no easier way? I would like to access either
asp:SqlDataSource (me.SqlDataSource1.something) or asp:GridView
(me.GridView1.something) instead I have to create a new
sqlcon,selectcommand,dataset,dataadapter....
Is there no easier way?
|
by: Jon Paal |
last post by:
how does a querystring value get passed to the selectcommand statement of an asp:SqlDataSource?
<asp:SqlDataSource id="propertyDataSource" Runat="Server"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
SelectCommand="SELECT * FROM WHERE propertyid = @id " />
|
by: =?Utf-8?B?TWFyaw==?= |
last post by:
Hi...
I'm trying to implement roles in various components (i.e. using different
sets of configuration depending, in this case, on which environment your in).
Pretty easy to add an AppSettings variable in most cases.
The thing that's causing me difficulty are the asp:SqlDataSource components
in an aspx page. Depending on the role setting, I have a different
connection string I want to use. Problem is that ConnectionString="<%$ %>"...
| |
by: bryant |
last post by:
Hi all.
I am new to ASP and working in Expression Web. The following query
displays the information I need in the gridview for a single record.
SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM", "OE_HDR"."SLS_MAN_NO",
"OE_HDR"."SLS_MAN_INITIALS", "OE_HDR"."ORD_DAT", "OE_HDR"."SHIP_DAT"
FROM "OE_HDR" WHERE ("OE_HDR"."ORD_NO"='174310')
I also have DropDownList1 working properly. For the WHERE portion of
|
by: KUVU |
last post by:
I am using
FormsAuthentication.SetAuthCookie(txtbox1.text,false) in my login page.
In my search.aspx i need to pass this login name to sqldatasource,delete commamd
i am using
<asp:CookiParameter> to pass the login name but don't know that to give in cookiename...
Can any one help me with this
|
by: E. Kwong |
last post by:
I just want to select records with a certain date field today's date:
<asp:SqlDataSource ID="src1" runat="server" ConnectionString="<%$
ConnectionStrings:xyz %>"
SelectCommand="SELECT * FROM WHERE ? "
OnSelected="src1_Selected">
<SelectParameters>
|
by: justice750 |
last post by:
Hi All,
I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field is not a null value. I am not using any code behind (C#) to bind the data or manipulate the data.
I have read that when there is a null value in the database that there is no record in the "dataset". Can anyone show me how to bind a value in the...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |