|
i'm just learning asp.net, n it's really frustrating as i can't seem to be able to connect to it..
this is a simple code i wrote to insert records into a table called 'Cars" AND A DATABASE Called "MotorSolutions..
here is my code:
<%@ Page Language="vb" debug="true" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
Sub Page_Load(Source As Object, E as EventArgs)
If Page.IsPostBack Then
lblTitle.Text = "Submit was successful"
Else
lblTitle.Text = "Leave the field blank and Submit"
End If
End Sub
Sub btn_click(Src As Object, E As EventArgs)
Dim DBConn as New SqlConnection
Dim DBAdd as New SqlCommand
DBConn = New SqlConnection("server=localhost;database=MotorSolutions;Uid=sa;pwd=5864jc;")
DBAdd.CommandText = "INSERT Into Cars(" _
& "Manufacturer, " _
& "Model) values (" _
& "'" & Replace(txtMF.Text, "'", "''") _
& "', " _
& "'" & Replace(txtModel.Text, "'", "''") _
& "')"
DBAdd.Connection = DBConn
DBAdd.Connection.Open
DBAdd.ExecuteNonQuery()
End Sub
<asp:label id="lblTitle" runat="SERVER">
Manufacturer: | | <asp:textbox id="txtMF" runat="server"> * <asp:requiredfieldvalidator
id="rfvManufacturer"
="" errormessage="Please enter the car manufacturer" runat="server" controltovalidate="txtMF" backcolor="#FFFF80" display="Dynamic"> | | Model : | | <asp:textbox id="txtModel" runat="server">
*
<asp:requiredfieldvalidator
id="rfvModel"
="" errormessage="Please enter the car model" runat="server" controltovalidate="txtModel" backcolor="#FFFF80" display="Dynamic"> | |
<asp:button id="btnSubmit" runat="SERVER" text="Submit" onclick="btn_click">
please can somebody help me...i keep getting this error:
Server Error in '/' Application.
SQL Server does not exist or access denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.
Source Error:
Line 28: & "')"
Line 29: DBAdd.Connection = DBConn
Line 30: DBAdd.Connection.Open
Line 31: DBAdd.ExecuteNonQuery()
Line 32:
Source File: c:\inetpub\wwwroot\motorsolutions\register2.aspx Line: 30
Stack Trace:
[SqlException: SQL Server does not exist or access denied.]
System.Data.SqlClient.SqlConnection.Open() +761
ASP.register2_aspx.btn_click(Object Src, EventArgs E) in c:\inetpub\wwwroot\motorsolutions\register2.aspx:30
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1263
Version Information: Microsoft .NET Framework Version:1.0.3705.0; ASP.NET Version:1.0.3705.0
is there something wrong with my connection string...i'd really appreciate it if anyone out there could test my code...my MotorSolutions database consists of only 2 fields:Manufacturer and Model...anyway, if u can't too it's ok..any meaningful feedback will do..Thanking you in advance.
|
|
|
|
|
The error message tells you "SQL Server does not exist or access denied".
This means that there are the following possibilities:
1. The SQL Server is not installed on the machine you refer to. In this case localhost. I've never seen a SQL Server connect to local host so you might want to change that to "(local)" or the name of your machine.
2. The SQL Server is not running. You can use the Microsoft SQL Server Service Manage to ensure that it is running properly.
3. Your log in credentials are wrong. You are using "sa" (a big security risk, if you don't mind me saying) in your web application. If the SQL Server was installed using "Windows Authentication" then the sa account is not accessible (because SQL Server logins are only available in mixed mode authentication). In this case you should use an appropriate trusted connection.
4. The password you supplied is incorrect (and, by the way, thanks for sharing your system administraton password with the world. You do know that with that level of access an attacker can gain control over your machine via SQL Server?).
Does this help?
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
I successfully use 'localhost' as the server in my connection string to SQL Server when I'm using Entrprize Library, but my friend has to change it when he puts my code on his machine. So, sometimes it works, and sometimes it doesn't. I havn't had time to look at why.
|
|
|
|
|
If he puts your code on his machine, localhost won't work to connect to SQL Server on *your* machine, if that's what you mean.
On the other hand, localhost should work at his machine to connect to SQL Server on *his* own machine. I've used localhost with SQL Server before, altough I usually use (local) .
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
I mean he can't connect using 'localhost' to connect to the database running on his own machine. It works fine for me to connect to a database on my machine, but he just changes the config string when I send him a new set of source code. It's not really a problem, but just anoying that it doesn't work. We are both using xp pro. The only differences I know of are that his is a laptop joined to a domain, and mine is a desktop in workgroup mode.
|
|
|
|
|
Thank you to everyone who helped me Luis, Scott, and especially too Colin..you made my day! it worked.. i changed it to (local) n it worked fine..
Thank you once again ...to everyone..i would have spent weeks..n not find the solution coz i was so convinced that my connection string was correct...and yes...about the password..point noted..
|
|
|
|
|
localhost is a TCPIP or DNS name for your local computer. It will only work in the connection string for SQL server if the TCPIP client transport is installed and enabled, and there is an active network connection (or loopback connection). "(local)" is an SQL Server name recognised as the local instance of the SQL server, and connection is made using shared memory (SQL2k) or named pipes (SQL7). The reason localhost sometimes works and sometimes doesn't is likely related to the way the networking on the computer is (or isn't) set up.
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke
|
|
|
|
|
How do I use a check box on an unbound database in vb.net?
BINARY
|
|
|
|
|
What do you want to do exactly ? Is it ASP.NET or a windows app ? What's the problem with the check box ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I got it figured out thanx
BINARY
|
|
|
|
|
Binary0110 wrote:
How do I use a check box
by clicking on it dude !!!
(hey, don't matter, it's just a joke)
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
I have a situation where i have a database with 19 tables in it.
I am required to develop an abstraction layer for this database, and have been juggling reams of SQL and .Net objects with an aim to get it working.
Fundamentaly I require each database table to be represented by a .Net object, and the functionality to build an object from the database, update / insert an object to the database.
Now, currently, i am writing the SQL and Code for this. However, it is taking bloody ages as some of the tables are pretty large, and getting all the fields and names set up in different fields is a monumental chore. (Not to mention dull)
The question i have is, are there any tools out there for converting a database (Sql Server in this case) into a collection of classes that represent the tables in the database and can be easily manipulated.
I have looked on the internet, but come up with only techniques to approach the problem.
Additional functionality as far as the objects concern is to be built later, but the core objects are still going to be required in their raw form.
Any help appreciated.
Regards
Tris
|
|
|
|
|
Here you go. You have all the readymade stuff here
http://sourceforge.net/projects/sqlom
Great tool.
|
|
|
|
|
|
I´ve got a report to show in VB.NET which i created using the embedded crystal reports designer that comes with visual studio. In that report i´ve got two tables in a dataset linked by a common field. The report has about 1000 rows and it takes too much time too load. And in top of all, cpu usage goes up to 99%... I read in google that in the crystal reports software (the full version) there is an option called "save data with report", that if it´s disabled can speed up the report load, but i can´t find it anywhere in visual studio.
Sorry about my english, and thanks for reading, i really need an answer!
|
|
|
|
|
I use .NET Framework 1.1, MS SQL server 2000, C# language
In my application, the function 'Backup data' executes 'BACKUP DATABASE...' to backup it's MS SQL Server database (in Database Server).
If my path/folder to backup file does not exit, it throw an exception: "Cannot open backup device..."
How can I the path or folder does not exist, so I can notify to end user.
Thanks.
None
|
|
|
|
|
Dear all
I use the "describe TABLENAME" command in SQL Plus with oracle to get the attributes of a table.
Can I use this command with MS Access and C#?
thanks
|
|
|
|
|
No. That is not a standard sql keyword, and is specific to Oracle IIRC.
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke
|
|
|
|
|
Hi there,
what is the best method to get a disconnected, read-only recordset into memory in ADO.Net? I've had a look at the SqlDataReader , which probably is option with the best performance, but it is not disconnected. The DataView and DataSet seem too fat for just forward-only, read-only access.
Any suggestions?
/matthias
I love deadlines. I like the whooshing sound they make as they fly by. [Douglas Adams]
|
|
|
|
|
If you are binding the data to a control the sqldatareader is the way to go. You can use the datadapter and a datatable if you don't want a dataset.
Here are two efficient examples. Remember use stored procs. Use the dispose method when possible. Use connection.dispose instead of connection.close. DataAdapters check for an open connection anyway so there is no need to open it.
<br />
Public Function GetDataTable(ByVal strConnectionString As String, ByVal strProcName As String) As DataTable<br />
Dim Conn As New SqlConnection<br />
Conn.ConnectionString = strConnectionString<br />
<br />
Dim Cmd As New SqlCommand<br />
Cmd.Connection = Conn<br />
Cmd.CommandType = CommandType.StoredProcedure<br />
Cmd.CommandText = strProcName<br />
Dim DA As New SqlDataAdapter<br />
DA.SelectCommand = Cmd<br />
Dim DT As New DataTable<br />
DA.Fill(DT)<br />
DA.Dispose()<br />
Cmd.Dispose()<br />
Return DT<br />
<br />
<br />
End Function<br />
<br />
<br />
Public Function FillDropDownList(ByRef DDL As DropDownList, ByVal strConnectionString As String, ByVal strProcName As String) As Boolean<br />
DDL.Items.Clear()<br />
Dim Conn As New SqlConnection<br />
Conn.ConnectionString = strConnectionString<br />
<br />
Dim Cmd As New SqlCommand<br />
Cmd.Connection = Conn<br />
Cmd.CommandType = CommandType.StoredProcedure<br />
Cmd.CommandText = strProcName<br />
Dim DR As SqlDataReader<br />
Conn.Open()<br />
DR = Cmd.ExecuteReader<br />
DDL.DataSource = DR<br />
DDL.DataValueField = DR.GetName(0)<br />
If DR.FieldCount > 1 Then<br />
DDL.DataTextField = DR.GetName(1)<br />
Else<br />
DDL.DataTextField = DR.GetName(0)<br />
End If<br />
<br />
DDL.DataBind()<br />
DR.Close()<br />
Conn.Dispose()<br />
Cmd.Dispose()<br />
DDL.Items.Insert(0, "")<br />
<br />
<br />
End Function<br />
"People who never make mistakes, never do anything."
My blog
http://toddsnotsoamazinglife.blogspot.com/
|
|
|
|
|
I would suggest having your own class abstracting the DataBase objects and use SqlDataReader to populate them.
The downside of using DataSet is that it contains the Schema information also and if the data size is huge, the performance hit is substantial.
This might be useful
http://sourceforge.net/projects/sqlom
|
|
|
|
|
Several times I have run into what I think is a bug in SQL Server 2000, but I haven't been able to verify it externally. Hopefully someone can help me do so, or identify what I'm doing wrong, or suggest an alternate technique to use.
Short descripttion: In a stored procedure, if I place a query inside an IF block and another inside the ELSE block the procedure works fine in SQL Server Query Analyzer. But... I get no results returned to an ADO recordset.
---------------------------
Long Description and code sample:
The purpose of the following stored procedure is to allow me to specify whether or not to limit the query to a specific VendorID value. The queries in the IF and ELSE blocks are exactly the same, except that the one in the ELSE block includes the VendorID filter in the WHERE clause.
When I execute this procedure from within SQL Query Analyzer, I get exactly the behavior I expect:
If I pass in 0 as the 3rd parameter, it will return any records matching the LastName and ZipCode parameters regardless of which Vendor: sp_PromoOrderSearch 'Doe', '98765', 0
If I pass in a non 0 number for VendorID, records will only be returned if all three values match across both tables: sp_PromoOrderSearch 'Doe', '98765', 2
So, the procedure works exactly as designed. The problem comes when I attempt to use this procedure from ADO. No matter what I pass in, I get no results at all. Now before you go wondering if I'm passing in parameters correctly, consider this: If I rip out the IF / THEN structure and only use one or the other query by itself, EACH of them works fine and returns records to my ADO recordset.
Right now my only solution is to use different stored procedures for each purpose, but I hate that. Any help?
Thanks in advance.
---------------------
CREATE PROCEDURE sp_PromoOrderSearch
@LastName varchar(255),
@ZipCode varchar(255),
@VendorID int
AS
-- Vendor 0 is global and can search among all vendors
IF (@VendorID = 0)
BEGIN
SELECT
pd.[custom_id], pd.[first_name], pd.[last_name],
pd.[address1], pd.[address2], pd.[phone_number],
pd.[email], pd.[qualified_date], v.[v_name]
FROM [promo_data] pd
JOIN promotion p ON p.p_code = pd.promo_code
JOIN vendor v ON v.v_id = p.v_id
WHERE
(
(pd.[last_name] = @LastName)
AND
(pd.[zip] = @ZipCode)
)
ORDER BY
pd.[last_name] ASC,
pd.[first_name] ASC
END
ELSE
BEGIN
SELECT
pd.[custom_id], pd.[first_name], pd.[last_name],
pd.[address1], pd.[address2], pd.[phone_number],
pd.[email], pd.[qualified_date], v.[v_name]
FROM [promo_data] pd
JOIN promotion p ON p.p_code = pd.promo_code
JOIN vendor v ON v.v_id = p.v_id
WHERE
(
(pd.[last_name] = @LastName)
AND
(pd.[zip] = @ZipCode)
AND
(v.v_id = @VendorID)
)
ORDER BY
pd.[last_name] ASC,
pd.[first_name] ASC
END
GO
--------
Anthony
|
|
|
|
|
I think you are doing something wrong with your ado code. I don't see anything wrong with the proc. I have written similar code with ado.net and it works fine. How are you retreiving the data, with a DataAdapter or DataReader?
"People who never make mistakes, never do anything."
My blog
http://toddsnotsoamazinglife.blogspot.com/
|
|
|
|
|
Thanks for your response.
The strange thing is, I did some additional testing after I sent that post and it turns out that even if I remove the IF condition and just have a single query in there, ANY command before my SELECT statement, even a simple "DECLARE @SomeVar int" won't break the proc in QA, but ADO still won't pick up the results. I played around with NOCOUNT ON / OFF, but to no avail. I'm totally befuddled.
Actually, the particular project I'm working on at the moment is in legacy ASP / VBScript. But, here's the code to retrive the data. And remember, if I change the proc, this very VBScript code works just fine.
--------
Dim p_objRecordSet
Dim p_objCommand
Set p_objRecordSet = Server.CreateObject("ADODB.RecordSet")
Set p_objCommand = Server.CreateObject("ADODB.Command")
With p_objCommand
.ActiveConnection = DBConnectionString
.CommandType = adCmdStoredProc
.Parameters.Append p_objCommand.CreateParameter("@LastName", adVarChar, adParamInput, 255, Trim(p_strLastName))
.Parameters.Append p_objCommand.CreateParameter("@ZipCode" , adVarChar, adParamInput, 255, Trim(p_strZipCode))
.Parameters.Append p_objCommand.CreateParameter("@VendorID", adInteger, adParamInput, 4, p_intVendorID)
End With
p_objRecordSet.CursorType = adOpenStatic
p_objRecordSet.Open p_objCommand
If p_objRecordSet.RecordCount > 0 Then
Do While Not p_objRecordSet.EOF
Response.Write(p_objRecordSet("address1"))
Response.Write("<BR>")
p_objRecordSet.MoveNext
Loop
End If
p_objRecordSet.Close
Set p_objRecordSet = Nothing
Set p_objCommand = Nothing
----------
Anthony
|
|
|
|
|