Hi,
I am using vs2005.
in the web.config, connectionString section I have written the folloing code:
<configuration>
<appSettings/>
<connectionStrings>
<add name="connstr" connectionString="data source=ARETE-1;integrated security=SSPI;persist security info=True;Database=INVOICE"/>
</connectionStrings> ................
On the code behind of the aspx page I have written the following code:
Dim conn As SqlConnection
conn = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings(connstr))
it gives an error saying that the connstr is not declared by a blue underline on connstr..
where am I going wrong..Please help urgent..
Regards,Hi friend,
This code is not correct.Using web.Config we give key value not name.Below code may be useful to u.
<configSections>
<section name="SMSettings" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
<SMSettings>
<add key="DataBase" value="dbServiceManual"/>
<add key="DataSource" value="IWAPPSVR\IWSQLDB"/>
<add key="ConnectionString" value="Persist Security Info=False;User ID=sa;Initial Catalog=dbServiceManual;Data Source=IWAPPSVR\IWSQLDB"/>
</SMSettings>
Hope it does.Try this one.Bye.....:) :)
I think you are not clear with my question..
Below is the web service that I have developed:
Public Function GetProducts(ByVal categoryname As String) As DataSet
Dim conn As New SqlConnection("data source=ARETE-1;integrated security=SSPI;persist security info=True;Database=northwind")
Dim adap As SqlDataAdapter
Dim ds As New DataSet
Dim strSelect As String
strSelect = "SELECT ProductName, UnitPrice, UnitsInStock, CategoryName " & _
"FROM Products, Categories WHERE Products.CategoryID = " & _
"Categories.CategoryID AND CategoryName = '" & categoryname & "'"
adap = New SqlDataAdapter(strSelect, conn)
'adap.SelectCommand.Parameters.Add("@.categoryname", SqlDbType.NVarChar, 15, categoryname)
adap.Fill(ds, "products")
Return ds
End Function
In the above code, I have included the connection string in the webservice itself.. how do I include it in the web.config file.. Not only that, I you see my first post, I have already included in the web.config file.. the problem is how do I call it.
Its very simple.. but I am not getting the proper systax probably for calling the connection string.
Regards,
Please do not double post!
Your setup is correct. But,
Dim conn As SqlConnection
conn = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("connstr"))
Thursday, March 22, 2012
Web.config+ConnectionString+Urgent+Sourabh
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment