|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
DB Connection in Config.web using VB calls.
<i><b>Originally posted by : steve schofield (steve@aspfree.com)</b></i><br />Hi all,<br /><br />All demos in the quickstart have a connection string right in the<br />Page_Onload sub. In the portal example this uses a config.web key that each<br />page can then call the connection string by a Key instead of embedding the<br />connection string in each page. This example in the portal example is done<br />in c#. This is my 1st attempt to do this in VB and hit a brick wall.<br /><br />In asp applications, I put in the global.asa (which all we know is nice and<br /><br />secure....HAHA) and had an include file that called the application root<br />that was set in global.asa on top of each page. Am I going about this the<br />wrong way? Below is the config.web, page i'm using, Error i'm getting and<br />what the compiler spits out<br /><br /><br />steve schofield<br />steve@aspfree.com<br /><br />Webmaster<br />http://aspfree.com<br /><br /><br /><br />Here is my config.web<br /><br /><configuration><br /> <security><br /> <authorization><br /> <allow users="*" /> <!-- Allow all (other) users --><br /> </authorization><br /> </security><br /> <configsections><br /> <add name="aspfreedsn"<br />type="System.Web.Configuration.DictionarySectionHandler"/><br /> </configsections><br /> <aspfreedsn><br /> <set key="aspfreedsn"<br />value="server=localhost;uid=connID;pwd=Password;database= devDB" /><br /> </aspfreedsn><br /></configuration><br /><br /><br /><br />Page that I'm trying to use.<br /><br /><%@ Import Namespace="System.Data" %><br /><%@ Import Namespace="System.Data.SQL" %><br /><br /><html><br /><script language="VB" runat="server"><br /><br /> Sub Page_Load(Sender As Object, E As EventArgs)<br /><br /> Dim DS As DataSet<br /> Dim MyConnection As SQLConnection<br /> Dim MyCommand As SQLDataSetCommand<br /><br /> String mydsn = (String) ((Hashtable)<br />Context.GetConfig("aspfreedsn"))("devDB")<br /> MyConnection = New SQLConnection(mydsn)<br /> MyCommand = New SQLDataSetCommand("select * from tblSiteName",<br />MyConnection)<br /> DS = New DataSet()<br /> MyCommand.FillDataSet(DS, "tblSiteName")<br /><br /> MyDataList.DataSource = DS.Tables("tblSiteName").DefaultView<br /> MyDataList.DataBind()<br /> End Sub<br /></script><br /><br /><br /><body><br /><br /><ASP
ataList id="MyDataList" runat="server"><br /> RepeatColumns="2"<br /> RepeatDirection="Horizontal"<br /> ItemStyle-Font-Size="10pt"<br /> ItemStyle-Font-Name="Verdana"<br /></ASP ataList><br /></body><br /></html><br /><br /><br />Error I'm getting<br /><br />Syntax Error:<br /><br /><br />Line 11: Dim MyCommand As SQLDataSetCommand<br />Line 12:<br />Line 13: String mydsn = (String) ((Hashtable)<br />Context.GetConfig("aspfreedsn"))("devDB")<br />Line 14: MyConnection = New SQLConnection(mydsn)<br />Line 15: MyCommand = New SQLDataSetCommand("select * from<br />tblSiteName", MyConnection)<br /><br /><br /><br />Here is what the compiler spits out<br /><br />C:WINNTsystem32> "vbc.exe" /t:library<br />/R:"C:WINNTComPlusv2000.14.1812System.Drawing.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.Text.RegularExpr essions.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.Web.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.Data.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.Web.Services.DLL "<br />/R:"C:WINNTComPlusv2000.14.1812System.Xml.Serializatio n.DLL"<br />/out:"c:inetpubwwwroot estcodegengen2292.dll" /optionexplicit- /debug-<br />"c:inetpubwwwroot estcodegengen2292.freehosts_aspx.vb"<br /><br />Microsoft (R) Visual Basic Compiler Version 7.00.8905 [NGWS version<br />2000.14.1812.10]<br />Copyright (C) Microsoft Corp 2000. All rights reserved.<br /><br />c:inetpubwwwroot estfreehosts.aspx(13) : error BC30035: Syntax error<br /><br /> String mydsn = (String) ((Hashtable)<br />Context.GetConfig("aspfreedsn"))("devDB")<br /> ~~~~~~<br /><br /><br /><br /><br /><br /> |
|
#2
|
|||
|
|||
|
<i><b>Originally posted by : D. R. Wolthuis (don.wolthuis@codejunkies.net)</b></i><br />How's it going? There was a couple things I found wrong. I put comments near the problem areas. It's kind of late so I may have made some spelling mistakes, I'll take another look in the morning to make sure I didn't leave anything out! Let me know if this works.<br /><br />______________________________________<br />Don R. Wolthuis, MCSD<br />CodeJunkies.Net / ASPNextGen.com<br />don.wolthuis@codejunkies.net<br /><br />Visit www.ASPNextGen.com or www.theFutureOfASP.com, both brought to you exclusively by CodeJunkies.Net, for tutorials and information on ASP+ - the next generation of Active Server Pages.<br /><br />http://www.codejunkies.net<br /><br /><br /><br /><br /><br /><configuration><br /><security><br /><authorization><br /><allow users="*" /> <!-- Allow all (other) users --><br /></authorization><br /></security><br /><br /><configsections><br /><!-- Missing a space after quote at the end, and 'You had your key and name the same I changed it to aspfreeConfig.--><br /> <add name="aspfreeConfig" type="System.Web.Configuration.DictionarySectionHandler" /> <br /></configsections><br /><br /><aspfreeConfig><br /><!-- I have seen set key and add key in this section so if it still doesn't work try add key--><br /><br /><set key="aspfreedsn"<br />value="server=localhost;uid=connID;pwd=Password;database= devDB" /><br /></aspfreeConfig><br /><br /></configuration><br /><br /><br /><br /><br /><br /><%@ Import Namespace="System.Data" %><br /><%@ Import Namespace="System.Data.SQL" %><br /><br /><html><br /><script language="VB" runat="server"><br /><br />Sub Page_Load(Sender As Object, E As EventArgs)<br /><br />Dim DS As DataSet<br />Dim MyConnection As SQLConnection<br />Dim MyCommand As SQLDataSetCommand<br /><br />'The DictionarySectionHandler returns a Hashtable so we create one.<br /> Dim htDSNInfo As Hashtable = Context.GetConfig("aspfreeConfig")<br /> <br />'Then access the key to return the value<br /> Dim mydsn = CStr(htDSNInfo("aspfreedsn") <br /><br />MyConnection = New SQLConnection(mydsn)<br />MyCommand = New SQLDataSetCommand("select * from tblSiteName",<br />MyConnection)<br />DS = New DataSet()<br />MyCommand.FillDataSet(DS, "tblSiteName")<br /><br />MyDataList.DataSource = DS.Tables("tblSiteName").DefaultView<br />MyDataList.DataBind()<br />End Sub<br /></script><br /><br /><br /><body><br /><br /><ASP
ataList id="MyDataList" runat="server"><br />RepeatColumns="2"<br />RepeatDirection="Horizontal"<br />ItemStyle-Font-Size="10pt"<br />ItemStyle-Font-Name="Verdana"<br /></ASP ataList><br /></body><br /></html><br /><br /><br /><br />------------<br />steve schofield at 8/26/2000 8:24:37 PM<br /><br />Hi all,<br /><br />All demos in the quickstart have a connection string right in the<br />Page_Onload sub. In the portal example this uses a config.web key that each<br />page can then call the connection string by a Key instead of embedding the<br />connection string in each page. This example in the portal example is done<br />in c#. This is my 1st attempt to do this in VB and hit a brick wall.<br /><br />In asp applications, I put in the global.asa (which all we know is nice and<br /><br />secure....HAHA) and had an include file that called the application root<br />that was set in global.asa on top of each page. Am I going about this the<br />wrong way? Below is the config.web, page i'm using, Error i'm getting and<br />what the compiler spits out<br /><br /><br />steve schofield<br />steve@aspfree.com<br /><br />Webmaster<br />http://aspfree.com<br /><br /><br /><br />Here is my config.web<br /><br /><configuration><br /> <security><br /> <authorization><br /> <allow users="*" /> <!-- Allow all (other) users --><br /> </authorization><br /> </security><br /> <configsections><br /> <add name="aspfreedsn"<br />type="System.Web.Configuration.DictionarySectionHandler"/><br /> </configsections><br /> <aspfreedsn><br /> <set key="aspfreedsn"<br />value="server=localhost;uid=connID;pwd=Password;database= devDB" /><br /> </aspfreedsn><br /></configuration><br /><br /><br /><br />Page that I'm trying to use.<br /><br /><%@ Import Namespace="System.Data" %><br /><%@ Import Namespace="System.Data.SQL" %><br /><br /><html><br /><script language="VB" runat="server"><br /><br /> Sub Page_Load(Sender As Object, E As EventArgs)<br /><br /> Dim DS As DataSet<br /> Dim MyConnection As SQLConnection<br /> Dim MyCommand As SQLDataSetCommand<br /><br /> String mydsn = (String) ((Hashtable)<br />Context.GetConfig("aspfreedsn"))("devDB")<br /> MyConnection = New SQLConnection(mydsn)<br /> MyCommand = New SQLDataSetCommand("select * from tblSiteName",<br />MyConnection)<br /> DS = New DataSet()<br /> MyCommand.FillDataSet(DS, "tblSiteName")<br /><br /> MyDataList.DataSource = DS.Tables("tblSiteName").DefaultView<br /> MyDataList.DataBind()<br /> End Sub<br /></script><br /><br /><br /><body><br /><br /><ASP ataList id="MyDataList" runat="server"><br /> RepeatColumns="2"<br /> RepeatDirection="Horizontal"<br /> ItemStyle-Font-Size="10pt"<br /> ItemStyle-Font-Name="Verdana"<br /></ASP ataList><br /></body><br /></html><br /><br /><br />Error I'm getting<br /><br />Syntax Error:<br /><br /><br />Line 11: Dim MyCommand As SQLDataSetCommand<br />Line 12:<br />Line 13: String mydsn = (String) ((Hashtable)<br />Context.GetConfig("aspfreedsn"))("devDB")<br />Line 14: MyConnection = New SQLConnection(mydsn)<br />Line 15: MyCommand = New SQLDataSetCommand("select * from<br />tblSiteName", MyConnection)<br /><br /><br /><br />Here is what the compiler spits out<br /><br />C:WINNTsystem32> "vbc.exe" /t:library<br />/R:"C:WINNTComPlusv2000.14.1812System.Drawing.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.Text.RegularExpr essions.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.Web.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.Data.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.Web.Services.DLL "<br />/R:"C:WINNTComPlusv2000.14.1812System.Xml.Serializatio n.DLL"<br />/out:"c:inetpubwwwroot estcodegengen2292.dll" /optionexplicit- /debug-<br />"c:inetpubwwwroot estcodegengen2292.freehosts_aspx.vb"<br /><br />Microsoft (R) Visual Basic Compiler Version 7.00.8905 [NGWS version<br />2000.14.1812.10]<br />Copyright (C) Microsoft Corp 2000. All rights reserved.<br /><br />c:inetpubwwwroot estfreehosts.aspx(13) : error BC30035: Syntax error<br /><br /> String mydsn = (String) ((Hashtable)<br />Context.GetConfig("aspfreedsn"))("devDB")<br /> ~~~~~~<br /><br /><br /><br /><br /><br /> |
|
#3
|
|||
|
|||
|
<i><b>Originally posted by : D. R. Wolthuis (don.wolthuis@codejunkies.net)</b></i><br />I knew I made an error.<br />This: <br />'Then access the key to return the value<br /><br /> Dim mydsn = CStr(htDSNInfo("aspfreedsn") <br /><br />Should be this:<br /><br />'Then access the key to return the value<br /> Dim mydsn as String = CStr(htDSNInfo("aspfreedsn")) <br /><br /><br />______________________________________<br />Don R. Wolthuis, MCSD<br />CodeJunkies.Net / ASPNextGen.com<br />don.wolthuis@codejunkies.net<br /><br />------------<br />D. R. Wolthuis at 8/27/2000 4:39:50 AM<br /><br />How's it going? There was a couple things I found wrong. I put comments near the problem areas. It's kind of late so I may have made some spelling mistakes, I'll take another look in the morning to make sure I didn't leave anything out! Let me know if this works.<br /><br />______________________________________<br />Don R. Wolthuis, MCSD<br />CodeJunkies.Net / ASPNextGen.com<br />don.wolthuis@codejunkies.net<br /><br />Visit www.ASPNextGen.com or www.theFutureOfASP.com, both brought to you exclusively by CodeJunkies.Net, for tutorials and information on ASP+ - the next generation of Active Server Pages.<br /><br />http://www.codejunkies.net<br /><br /><br /><br /><br /><br /><configuration><br /><security><br /><authorization><br /><allow users="*" /> <!-- Allow all (other) users --><br /></authorization><br /></security><br /><br /><configsections><br /><!-- Missing a space after quote at the end, and 'You had your key and name the same I changed it to aspfreeConfig.--><br /> <add name="aspfreeConfig" type="System.Web.Configuration.DictionarySectionHandler" /> <br /></configsections><br /><br /><aspfreeConfig><br /><!-- I have seen set key and add key in this section so if it still doesn't work try add key--><br /><br /><set key="aspfreedsn"<br />value="server=localhost;uid=connID;pwd=Password;database= devDB" /><br /></aspfreeConfig><br /><br /></configuration><br /><br /><br /><br /><br /><br /><%@ Import Namespace="System.Data" %><br /><%@ Import Namespace="System.Data.SQL" %><br /><br /><html><br /><script language="VB" runat="server"><br /><br />Sub Page_Load(Sender As Object, E As EventArgs)<br /><br />Dim DS As DataSet<br />Dim MyConnection As SQLConnection<br />Dim MyCommand As SQLDataSetCommand<br /><br />'The DictionarySectionHandler returns a Hashtable so we create one.<br /> Dim htDSNInfo As Hashtable = Context.GetConfig("aspfreeConfig")<br /> <br />'Then access the key to return the value<br /> Dim mydsn = CStr(htDSNInfo("aspfreedsn") <br /><br />MyConnection = New SQLConnection(mydsn)<br />MyCommand = New SQLDataSetCommand("select * from tblSiteName",<br />MyConnection)<br />DS = New DataSet()<br />MyCommand.FillDataSet(DS, "tblSiteName")<br /><br />MyDataList.DataSource = DS.Tables("tblSiteName").DefaultView<br />MyDataList.DataBind()<br />End Sub<br /></script><br /><br /><br /><body><br /><br /><ASP
ataList id="MyDataList" runat="server"><br />RepeatColumns="2"<br />RepeatDirection="Horizontal"<br />ItemStyle-Font-Size="10pt"<br />ItemStyle-Font-Name="Verdana"<br /></ASP ataList><br /></body><br /></html><br /><br /><br /><br />------------<br />steve schofield at 8/26/2000 8:24:37 PM<br /><br />Hi all,<br /><br />All demos in the quickstart have a connection string right in the<br />Page_Onload sub. In the portal example this uses a config.web key that each<br />page can then call the connection string by a Key instead of embedding the<br />connection string in each page. This example in the portal example is done<br />in c#. This is my 1st attempt to do this in VB and hit a brick wall.<br /><br />In asp applications, I put in the global.asa (which all we know is nice and<br /><br />secure....HAHA) and had an include file that called the application root<br />that was set in global.asa on top of each page. Am I going about this the<br />wrong way? Below is the config.web, page i'm using, Error i'm getting and<br />what the compiler spits out<br /><br /><br />steve schofield<br />steve@aspfree.com<br /><br />Webmaster<br />http://aspfree.com<br /><br /><br /><br />Here is my config.web<br /><br /><configuration><br /> <security><br /> <authorization><br /> <allow users="*" /> <!-- Allow all (other) users --><br /> </authorization><br /> </security><br /> <configsections><br /> <add name="aspfreedsn"<br />type="System.Web.Configuration.DictionarySectionHandler"/><br /> </configsections><br /> <aspfreedsn><br /> <set key="aspfreedsn"<br />value="server=localhost;uid=connID;pwd=Password;database= devDB" /><br /> </aspfreedsn><br /></configuration><br /><br /><br /><br />Page that I'm trying to use.<br /><br /><%@ Import Namespace="System.Data" %><br /><%@ Import Namespace="System.Data.SQL" %><br /><br /><html><br /><script language="VB" runat="server"><br /><br /> Sub Page_Load(Sender As Object, E As EventArgs)<br /><br /> Dim DS As DataSet<br /> Dim MyConnection As SQLConnection<br /> Dim MyCommand As SQLDataSetCommand<br /><br /> String mydsn = (String) ((Hashtable)<br />Context.GetConfig("aspfreedsn"))("devDB")<br /> MyConnection = New SQLConnection(mydsn)<br /> MyCommand = New SQLDataSetCommand("select * from tblSiteName",<br />MyConnection)<br /> DS = New DataSet()<br /> MyCommand.FillDataSet(DS, "tblSiteName")<br /><br /> MyDataList.DataSource = DS.Tables("tblSiteName").DefaultView<br /> MyDataList.DataBind()<br /> End Sub<br /></script><br /><br /><br /><body><br /><br /><ASP ataList id="MyDataList" runat="server"><br /> RepeatColumns="2"<br /> RepeatDirection="Horizontal"<br /> ItemStyle-Font-Size="10pt"<br /> ItemStyle-Font-Name="Verdana"<br /></ASP ataList><br /></body><br /></html><br /><br /><br />Error I'm getting<br /><br />Syntax Error:<br /><br /><br />Line 11: Dim MyCommand As SQLDataSetCommand<br />Line 12:<br />Line 13: String mydsn = (String) ((Hashtable)<br />Context.GetConfig("aspfreedsn"))("devDB")<br />Line 14: MyConnection = New SQLConnection(mydsn)<br />Line 15: MyCommand = New SQLDataSetCommand("select * from<br />tblSiteName", MyConnection)<br /><br /><br /><br />Here is what the compiler spits out<br /><br />C:WINNTsystem32> "vbc.exe" /t:library<br />/R:"C:WINNTComPlusv2000.14.1812System.Drawing.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.Text.RegularExpr essions.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.Web.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.Data.DLL"<br />/R:"C:WINNTComPlusv2000.14.1812System.Web.Services.DLL "<br />/R:"C:WINNTComPlusv2000.14.1812System.Xml.Serializatio n.DLL"<br />/out:"c:inetpubwwwroot estcodegengen2292.dll" /optionexplicit- /debug-<br />"c:inetpubwwwroot estcodegengen2292.freehosts_aspx.vb"<br /><br />Microsoft (R) Visual Basic Compiler Version 7.00.8905 [NGWS version<br />2000.14.1812.10]<br />Copyright (C) Microsoft Corp 2000. All rights reserved.<br /><br />c:inetpubwwwroot estfreehosts.aspx(13) : error BC30035: Syntax error<br /><br /> String mydsn = (String) ((Hashtable)<br />Context.GetConfig("aspfreedsn"))("devDB")<br /> ~~~~~~<br /><br /><br /><br /><br /><br /> |
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > DB Connection in Config.web using VB calls. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|