Hi all,
I think I am very close to suceeding but I am getting an error message.
The Scenario is I am using the FileUpload tool, Grabbing the Excel File and hitting an upload button.
Here is the code...
ASP
- <asp:FileUpload ID="FileUpload1" runat="server" />
- <asp:Button ID="Button1" runat="server" Text="Upload Spreadsheet" OnClick="Upload"/>
- <asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label>
Code Behind
- protected void Upload(object sender, EventArgs e)
- {
- string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
- string contentType = FileUpload1.PostedFile.ContentType;
- using (Stream fs = FileUpload1.PostedFile.InputStream)
- {
- using (BinaryReader br = new BinaryReader(fs))
- {
- byte[] bytes = br.ReadBytes((Int32)fs.Length);
- string constr = ConfigurationManager.ConnectionStrings["SalesConnectionString"].ConnectionString;
- using (SqlConnection con = new SqlConnection(constr))
- {
- con.Open();
- string query = "INSERT INTO Upload VALUES (@Name, @ContentType)";
- using (SqlCommand cmd = new SqlCommand(query))
- {
- cmd.Connection = con;
- cmd.Parameters.AddWithValue("@Name", filename);
- cmd.Parameters.AddWithValue("@ContentType", contentType);
- cmd.ExecuteNonQuery();
- con.Close();
- }
- }
- }
- }
- }
However I am getting the Error
Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Is it because I am pointing at my C: Drive rather than a Network?