473,394 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Use of the connectionstring from my web.config

Hello, I'd like to improve this code, because there's is a better way to use
the connectionstring from my web.config file instead of using:

Dim objConn As New
OleDbConnection("Provider=SQLNCLI;Server=db2fx981\ comware;Database=SIP;Trusted_Connection=yes;")

This is my code:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">

Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
Hidden1.Value = Request.QueryString("id")
If IsPostBack() Then
Dim objConn As New
OleDbConnection("Provider=SQLNCLI;Server=db2fx981\ comware;Database=SIP;Trusted_Connection=yes;")
objConn.Open()
Dim sSQL, Resul As String
sSQL = "Insert into Propuesta (idprospecto, Objeto, fecharecibo,
fechaentrega, idusuario, idestado ) values ('" & Hidden1.Value & "', '" &
TxtObjeto.Text & "', " & TxtFechaRecibo.Text & ", " & TxtFechaCierre.Text &
", '" & DropDownVendedor.SelectedValue & "', '" &
DropDownEstado.SelectedValue & "')"
Response.Write(sSQL)
'Response.End()
Dim objCmd As New OleDbCommand(sSQL, objConn)

Resul = objCmd.ExecuteNonQuery
If Resul Then
Label1.Visible = True
End If
End If
End Sub
</script>

Thx.
Oct 29 '08 #1
6 4011
"egsdar" <eg****@discussions.microsoft.comwrote in message
news:9A**********************************@microsof t.com...
Hello, I'd like to improve this code, because there's is a better way to
use
the connectionstring from my web.config file instead of using:

Dim objConn As New
OleDbConnection("Provider=SQLNCLI;Server=db2fx981\ comware;Database=SIP;Trusted_Connection=yes;")
http://weblogs.asp.net/owscott/archi....net-v2.0.aspx
http://www.connectionstrings.com/?carrier=sqlserver2005

AAMOI, is there a reason that you're using the SQL Native Client instead of
the SQL Server .NET data provider?
http://forums.microsoft.com/TechNet/...0214&SiteID=17
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 29 '08 #2
AAMOI, is there a reason that you're using the SQL Native Client instead of
the SQL Server .NET data provider?
Well, there's no reason at all, just i found that, do you have any
suggestions?

"Mark Rae [MVP]" wrote:
"egsdar" <eg****@discussions.microsoft.comwrote in message
news:9A**********************************@microsof t.com...
Hello, I'd like to improve this code, because there's is a better way to
use
the connectionstring from my web.config file instead of using:

Dim objConn As New
OleDbConnection("Provider=SQLNCLI;Server=db2fx981\ comware;Database=SIP;Trusted_Connection=yes;")

http://weblogs.asp.net/owscott/archi....net-v2.0.aspx
http://www.connectionstrings.com/?carrier=sqlserver2005

AAMOI, is there a reason that you're using the SQL Native Client instead of
the SQL Server .NET data provider?
http://forums.microsoft.com/TechNet/...0214&SiteID=17
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 29 '08 #3
"egsdar" <eg****@discussions.microsoft.comwrote in message
news:3C**********************************@microsof t.com...
>AAMOI, is there a reason that you're using the SQL Native Client instead
of
the SQL Server .NET data provider?

Well, there's no reason at all, just I found that, do you have any
suggestions?
Yes - use the SQL .NET data provider so that you can use SqlClient instead
of OleDb...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 29 '08 #4
there is a <connectionStringssection in the web.config. add one for your
database then:

var s = ConfigurationManager.ConnectionStrings["myConn"].ConnectionString;

also you should read about sql injection because your code has this huge
security hole.

-- bruce (sqlwork.com)
"egsdar" wrote:
Hello, I'd like to improve this code, because there's is a better way to use
the connectionstring from my web.config file instead of using:

Dim objConn As New
OleDbConnection("Provider=SQLNCLI;Server=db2fx981\ comware;Database=SIP;Trusted_Connection=yes;")

This is my code:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">

Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
Hidden1.Value = Request.QueryString("id")
If IsPostBack() Then
Dim objConn As New
OleDbConnection("Provider=SQLNCLI;Server=db2fx981\ comware;Database=SIP;Trusted_Connection=yes;")
objConn.Open()
Dim sSQL, Resul As String
sSQL = "Insert into Propuesta (idprospecto, Objeto, fecharecibo,
fechaentrega, idusuario, idestado ) values ('" & Hidden1.Value & "', '" &
TxtObjeto.Text & "', " & TxtFechaRecibo.Text & ", " & TxtFechaCierre.Text &
", '" & DropDownVendedor.SelectedValue & "', '" &
DropDownEstado.SelectedValue & "')"
Response.Write(sSQL)
'Response.End()
Dim objCmd As New OleDbCommand(sSQL, objConn)

Resul = objCmd.ExecuteNonQuery
If Resul Then
Label1.Visible = True
End If
End If
End Sub
</script>

Thx.
Oct 29 '08 #5
http://www.connectionstrings.com/?carrier=sqlserver2005

SqlConnection (.NET)

"egsdar" <eg****@discussions.microsoft.comwrote in message
news:3C**********************************@microsof t.com...
AAMOI, is there a reason that you're using the SQL Native Client instead
of
the SQL Server .NET data provider?
Well, there's no reason at all, just i found that, do you have any
suggestions?

"Mark Rae [MVP]" wrote:
>"egsdar" <eg****@discussions.microsoft.comwrote in message
news:9A**********************************@microso ft.com...
Hello, I'd like to improve this code, because there's is a better way
to
use
the connectionstring from my web.config file instead of using:

Dim objConn As New
OleDbConnection("Provider=SQLNCLI;Server=db2fx981\ comware;Database=SIP;Trusted_Connection=yes;")

http://weblogs.asp.net/owscott/archi....net-v2.0.aspx
http://www.connectionstrings.com/?carrier=sqlserver2005

AAMOI, is there a reason that you're using the SQL Native Client instead
of
the SQL Server .NET data provider?
http://forums.microsoft.com/TechNet/...0214&SiteID=17
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


Oct 29 '08 #6
"egsdar" <eg****@discussions.microsoft.comwrote in message
news:1D**********************************@microsof t.com...
Thanks all for your support, but unfortunately after the changes I'm
receiving
this error message:
Keyword not supported: 'provider'.
As previously advised, use SqlClient rather than SQLNCLI...

<connectionStrings>
<add name="SIPConnectionString" connectionString="Data
Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=SSPI;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data.SqlClient" %>
Dim objConn As New
OleDbConnection(ConfigurationManager.ConnectionStr ings("SIPConnectionString").ConnectionString)
Dim objConn As New
SqlConnection(ConfigurationManager.ConnectionStrin gs("SIPConnectionString").ConnectionString)
Dim objCmd As New OleDbCommand(sSQL, objConn)
Dim objCmd As New SqlCommand(sSQL, objConn)

Also, as mentioned by another poster, your code is wide open to SQL
Injection. Whatever you do, do not deploy this on a public webserver until
you've fixed that...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 30 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Devante | last post by:
Hi, I am fairly new to ASP.NET and have been working on a web form that will allow a user to upload images to a database. I have found a sample web form that I have been trying to get working,...
2
by: G. Dean Blake | last post by:
We currently distribute a web application to serveral servers for a customer. We have been putting the connection string in our web.config file under <appSettings> <add...
6
by: Tony | last post by:
Dear All, When I run an example program on the http://www.dotnetjunkies.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/data/datagrid1.src&file=VB\datagrid1.aspx&font=3 ...
4
by: Shapper | last post by:
Hello, I have this connectionString in a DataReader: Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\db.mdb" It's working fine. Now i...
10
by: Laura K | last post by:
Tried all kinds of things. I get the error. The ConnectionString property has not been initialized. Any help appreciated. ...
2
by: tshad | last post by:
I am trying to create an application in my VS 2002 application. I took some of the code from my web page where it works fine. I can connect fine from my Sql Query Analyser to both my local Sql...
3
by: Jim Andersen | last post by:
Hi, I would appreciate if someone could explain this behaviour, and maybe offer a better solution. I have been working with the GridView control. And SqlDataSource. It works great if I do:...
5
by: Arpan | last post by:
I created a System DSN named "NETData" for a SQL Server 2005 Express database. Now to make use of this System DSN to access records in the DB table, this is how I framed the ConnectionString: ...
1
by: ginkim | last post by:
Is there a way to grab the connectionstring value from the web.config in another project? I created a DataAccess layer to store my typed dataset and it automatically created settings.settings and...
5
by: Radu | last post by:
Hi. In a repeater I have as ItemTemplate the following, among others, and everything works great: <asp:SqlDataSource ID="LocationSqlDataSource" SelectCommand="SELECT blah-blah-blah"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.