Showing posts with label machine. Show all posts
Showing posts with label machine. Show all posts

Monday, March 26, 2012

Noob to VWD 2005 - Insert from textbox into SQL DB

I have followed all the tutorials and I think I have a pretty good grasp on how to get info from the SQL database running on my machine in the App Data directory. My question is simple and probably the answer is nested in the 148 pages of this very informative forum.

How do I take the 15 textbox fields worth of data and insert them into the SQL db? I am pretty familiar with general sql concepts (mysql, mssql, postgresql), but I have only been in this IDE for about a week now and I need to get my project up and running quickly. I am just unfamiliar with VB in general, but I do understand the object.method concept.

I gathered that I need to make the insert statement part of the button click "event". I cannot find any good "starter" documentation on getting this process to work. I understand the grid and form and detail view really well and have tested my 2nd app with success, but it requires the db to be populated by a web front end. I have read a few MSDN links but they are not helping much, they just keep linking me back to grid and detal and form views.


Help? Please? Pretty Please?


- Chris

roninuta:

I have followed all the tutorials and I think I have a pretty good grasp on how to get info from the SQL database running on my machine in the App Data directory. My question is simple and probably the answer is nested in the 148 pages of this very informative forum.

How do I take the 15 textbox fields worth of data and insert them into the SQL db? I am pretty familiar with general sql concepts (mysql, mssql, postgresql), but I have only been in this IDE for about a week now and I need to get my project up and running quickly. I am just unfamiliar with VB in general, but I do understand the object.method concept.

I gathered that I need to make the insert statement part of the button click "event". I cannot find any good "starter" documentation on getting this process to work. I understand the grid and form and detail view really well and have tested my 2nd app with success, but it requires the db to be populated by a web front end. I have read a few MSDN links but they are not helping much, they just keep linking me back to grid and detal and form views.


Help? Please? Pretty Please?


- Chris

This link...

http://www.WebLogicArts.com/DemoSqlServerDatabase01.aspx

...is a working sample with source code that shows one simple way to CreateOne/ UpdateOne/ DeleteOne/ RetrieveOne/ RetrieveAll using ASP.NET and SQL Sever 2000.

HTH.

Thank you.

-- Mark Kamoski

|||

Ok, there are two very simple ways you can do this.

1) Using the SQLDataSource object and after creating the connection using the GUI. You can find the SqlDataSource control in the toolbox. Although easy to use I don't like it too much, prefer writing SLQ statements on my own allows for more flexibility. However, to use the SqlDataSource object you are forced to create an SQL statement using the GUI, but this can be countermanded. So what I do is use the SQLDataSource object's SelectCommand and use its SelectCommand method to write my own SQL statement. Basically SQLDataSource1.SelectCommand = "Select * from whatever". To include textboxes, like in a search your SQL statement should look like this

"Select * from Table WHERE Table.Column = '" & textbox1.text & "'"

You can extrapolate to Insert and Update.

2) Another way of using SQL in VWD2005E is to call ADODB objects. I find this the best method to do inserts and such. First you have to make a reference to the DLL, to do this you go to Website->Add Reference click on the COM tab and find Microsoft ActiveX Data Objects, pick one and click OK. To use ADODB you first declare it then set the connection string (I usually copy it from the SQLDataSource Object), and execute your sql command.

Dim Conn as ADODB.Connection

Conn.ConnectionString = "Provider..."

Conn.Execute(InsertCommand)

Holler at me for any clarifications

|||I forgot, for 2 after Dim Conn as ADODB.Connection you have to put Conn = new ADODB.Connection|||You can try this one at your button submit click event using text1 as your control.

Dim datasourceAsNew SqlDataSource()

datasource.ConnectionString = ConfigurationManager.ConnectionStrings("YourConnectionString").ToString()

datasource.InsertCommandType = SqlDataSourceCommandType.Text

datasource.InsertCommand ="INSERT INTO YourTable (YourTableField) VALUES (@.YourTableField)"

datasource.InsertParameters.Add(

"YourTableField", Text1.Text)

|||You can try this one at your button submit click event using text1 as your control.

Dim datasourceAsNew SqlDataSource()

datasource.ConnectionString = ConfigurationManager.ConnectionStrings("YourConnectionString").ToString()

datasource.InsertCommandType = SqlDataSourceCommandType.Text

datasource.InsertCommand ="INSERT INTO YourTable (YourTableField) VALUES (@.YourTableField)"

datasource.InsertParameters.Add(

"YourTableField", Text1.Text)

|||

this last example was awesome. It was implistic and really helped. I understand much more now. I new that I was going to have to use the parameters.add functionality. I think I am messing up on my connection string though and it is probably just not set correctly. I get an unhandled exception here is the error message:

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_1cnoj4u7"
StackTrace:
at _Default.SendForm_Click(Object sender, EventArgs e) in D:\Documents and Settings\ronin\My Documents\Visual Studio 2005\WebSites\ADRequest\Default.aspx.vb:line 20
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Here is line 20 - the connection string:

datasource.ConnectionString = ConfigurationManager.ConnectionStrings("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\adrequest.mdf;Integrated Security=True;User Instance=True").ToString()

I am using a built in SQLDB file that comes with VWD2005E, and the file is called adrequest.mdf, what am I missing here.

TIA,

Chris

|||

You are wrong with declaring with your connection string. Your connection string name must be like in my part:

phiwugdatasource.ConnectionString = ConfigurationManager.ConnectionStrings("phiwugConnectionString1").ToString()


To find the name of your connection string, try to do this, add a blank web form on your project, go to database explorer and go to the table of your database, click the table and drag and drop this to the blank web form. You will see that it will create a table on your blank web form and a control name SqlDataSource - SqlDataSource1. Click it then click the arrow next to it and you will see Configure Data Source and click it. Next a wizard will appear. The connection string name that will appear on the drop down list box is the connection string name you will write on it.

Be sure to mark as answer on the post you think that answers your question so that the poster will have credit for it. Don't hesitate to inquire.

Best regards,

|||

This may be a silly question but given this code:

Dim datasource As New SqlDataSource()
datasource.ConnectionString = ConfigurationManager.ConnectionStrings("connection2").ToString()
datasource.InsertCommandType = SqlDataSourceCommandType.Text
datasource.InsertCommand = "INSERT INTO ticket (sr) VALUES (@.srnum)"
datasource.InsertParameters.Add("srnum", TextBoxSRNum.Text)

is the data actually being posted to the DB or is the insert statement just being setup? Do I need to actually execute the statement through another line?

TIA - Chris

|||

Nevermind

I just added datasurce.Insert() to the end of the event - that fixed it - thanks everyone for helping out!

- Chris

|||

You can even add this one and put your datasource.insert() on a structured error handling procedure:

Dim

rowsaffectedAsIntegerTry

rowsaffected = datasource.Insert()

Catch exAs Exception'TODO: Probably write a windows error log

Server.Transfer(

"error.aspx") <--create a web form for error messages/siteFinally

datasource =

Nothing

EndTry

If rowsaffected <> 1Then

Server.Transfer(

"error.aspx") <--create a web form for error messages/siteElse

Server.Transfer(

"success.aspx") <--create a web form for success messages/site

EndIf

Friday, March 23, 2012

Noob question about SQL Server Express used local and on server.

I have just started looking at using a database with my web site. If I have SQL Server Express with the Advanced Services on my local machine and I use it to make interactive pages, can I use the schema and tables on the actual web site on a remote server? If so does that server need to have SQL Server Express installed too?

A link to a tutorial or reference that goes into some detail would be awsome!

Thanks everyone!

Yes, you will need SQL Express and the Advanced Services installed on the server. Depending on how you have it setup, you should just be able to copy the contents of th App_Data folder over and it should work. This page should provide further information:http://msdn2.microsoft.com/en-us/library/ms165668.aspx

Non-standard port through router

Here's my setup. I have an SQL server machine with a local LAN ip. I have
a router with an internet IP. I configured the router to pass external port
5000 through to the sql machine's ip on port 1433. When I try to connect to
the sql server using the router's IP and port 5000 I get a timeout. I can
telnet to the router's IP and port 5000 (get a blank screen, but connection
succeeds).
Does anyone know why I would be getting a timeout? If I (internaly) connect
to the sql machine's local LAN IP port 1433 I can access the SQL server with
no problems.
Hi Lee,
If you get a blank black screen from telnet <MachineName>_or_<IP> <Port
Number>, then you have succeeded in connecting over TCP/IP to the ROUTER
port. We are not able to say it connects to SQL Server's TCP/IP port
successfully. I still think your mapping in router is not configured
correctly.
Secondly, what client tools you used to connect SQL Server? Query Analyzer?
Sincerely yours,
Michael Cheng
Online Partner Support Specialist
Partner Support Group
Microsoft Global Technical Support Center
Get Secure! - http://www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Please reply to newsgroups only, many thanks!
sql

Wednesday, March 21, 2012

Non-Paged Memory leak

One of our application which uses ODBC to access SQL2000
Sp3 database (on the same machine) is leaking Non-paged
Pool memory (continuously). Can this be due to ODBC driver
problem as reported in article "814410 FIX"?
THis is happening only on few machines (SQL2000 Sp3 on
Win2K advanced Server Sp4).
Will SQL2000 Sp3a solve this problem?
I am not able to consistantly see the problem.
We observed NonPaged leak on Task Monitor after we saw
error with Event id 2019 in an event log of a machine
earlier.Dinesh
SP3a does contain a fix for 814410. See:
http://support.microsoft.com/?kbid=306908
Hope this helps.
Sal Terillo
"Dinesh" <dineshks@.infosys.com> wrote in message
news:0ac301c3617b$25682600$a501280a@.phx.gbl...
> One of our application which uses ODBC to access SQL2000
> Sp3 database (on the same machine) is leaking Non-paged
> Pool memory (continuously). Can this be due to ODBC driver
> problem as reported in article "814410 FIX"?
> THis is happening only on few machines (SQL2000 Sp3 on
> Win2K advanced Server Sp4).
> Will SQL2000 Sp3a solve this problem?
> I am not able to consistantly see the problem.
> We observed NonPaged leak on Task Monitor after we saw
> error with Event id 2019 in an event log of a machine
> earlier.
>sql

Saturday, February 25, 2012

No. of connections available for Per Seat License

We have a MSSQL with per seat license of 20. The MSSQL is sitting in the same machine as the asp.net. Does that mean that the the no. of connections and Max Pool Size are limited up to 20 only?
Thanks,Ben
I don't know that any of us here are going to be willing to venture a guess on the often confusing legalities of SQL Server licensing. I can recommend this link as a starting point for your research:SQL Server 2000 Pricing and Licensing. Be sure to look at theSQL2KLic.doc in the upper righthand corner.

No witness, primary shutsdown, bring failover online

First of all, Great webcast today. My question is, I have everything up and running and would like to know what to do when the machine my primary is on quits or has a some type of disaster. Do I need to manually run recovery on each db that was mirrored? I'm not currently running a witness.

thanks

No, you don't need to recover anything but depending on which mode you are running you will need to iether manually initiate a failover from server A to B or force the service from server A to B because you are running without a witness.

do you know what mode you are running, high-performance or high-protection?

|||Everything runs in high Safty and just to be clear I'm looking at the scenario where the primary just dies.|||

ok, so you're running high protection mode.

I will have to correct myself here first, running in either high performance or high protection requires that you force service from server A to B. In books Online, look up the topics:

Forced Service (with Possible Data Loss)

and

How to: Force Service in a Database Mirroring Session (Transact-SQL)

these will explain in more detail than I ever could!

Hope this helps

|||

This is correct. If the principal cannot be contacted, then the way to make the databases available on the mirror is to turn off mirroring or to issue a "FORCE_SERVICE_ALLOW_DATA_LOSS"

Thanks,

Mark