Welcome to WebmasterWorld Guest from 54.226.133.245

Forum Moderators: ocean10000

Message Too Old, No Replies

Connecting to Mysql remote server using asp:Fileupload

     
9:57 pm on May 1, 2011 (gmt 0)

New User

5+ Year Member

joined:Dec 4, 2009
posts: 17
votes: 0


Using asp:FileUpload I am trying to upload a file to my remote MySql database.(Table Name:files: Field Name filename.) But canít figure out the correct connection code and how to insert into the below FileUpload code.

My current connect which works with other applications is located in web.config:
<add name="ConnStringName" connectionString="Database=#*$!xx_data;Data Source=xx.#*$!.xx.x;port=#*$!x;UId=#*$!#*$!x;Password=#*$!#*$!;"
providerName="MySql.Data.MySqlClient" />

FileUpload code:

<script type="text/vbscript" runat="server">
Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs("C:\Uploads\" & _
FileUpload1.FileName)
Label1.Text = "File name: " & _
FileUpload1.PostedFile.FileName & "<br>" & _
"File Size: " & _
FileUpload1.PostedFile.ContentLength & " kb<br>" & _
"Content type: " & _
FileUpload1.PostedFile.ContentType
Catch ex As Exception
Label1.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
Label1.Text = "You have not specified a file."
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Upload Files</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" /><br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Upload File" />&nbsp;<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label></div>
</form>
</body>
</html>
I am locating the file to be uploaded via the browse button.

Help would be appreciated.

latoc
1:56 pm on May 2, 2011 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:852
votes: 0


Exploring MySQL in the Microsoft .NET Environment [dev.mysql.com] Shows a couple of ways of setting up the Data Connection coding to work with MYSQL depending which Library you use to connect with.

As for the file uploading part. Are you trying to upload the file into the database? or are you just trying to save the path to the uploaded file in the database?
3:28 pm on May 2, 2011 (gmt 0)

New User

5+ Year Member

joined:Dec 4, 2009
posts: 17
votes: 0


Thank for your reply and suggested lnk.

I am trying to create a form to upload selected file(s) direct to my database by clicking an upload button.
latoc
3:07 pm on May 9, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 12, 2002
posts:857
votes: 0


Before trying to write anything to the DB, I would make sure I can connect okay to it by reading something from the DB first.

If I'm not mistaken, not all servers let you connect remotely to a mysql db - sometimes you have to set some permissions.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members