I posted the other day regarding a solution i needed to design, im new to development an asp,net and built a local post office search tool using asp.net 2. vb in visual studio, using an sql express mdf database(this means the database is transferable with the solution even if the server doesnt have sql server on it) The app works fine, users can search, admins can edit data, insert and delete. The site also has membership and role management.
My problem is that i needed to be able to have a user browse a csv file and upload it into a datagrid and then the database. ive got the following but recieve an error when running it.
upload.aspx
Expand|Select|Wrap|Line Numbers
- %@ Page Language="VB"%>
- <%@ Import Namespace="system.io" %>
- <%@ Import Namespace="System.Data" %>
- <%@ Import Namespace="system.data.sqlclient" %>
- <%@ Import Namespace="system.configuration" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <script runat="server">
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
- If (IsPostBack) Then
- Grid.Visible = True
- Else
- Grid.Visible = False
- End If
- End Sub
- Protected Sub UploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
- If OpenFileDialog1.HasFile Then
- Dim fi As New FileInfo(OpenFileDialog1.FileName)
- Dim strConn As String = System.Configuration.ConfigurationManager.AppSettings("connectionstring") & fi.DirectoryName
- Dim connection As New SqlConnection("strConn")
- Dim MySql As String = "SELECT * FROM " & fi.Name
- Dim objDR As SqlDataReader
- Dim Cmd As New SqlCommand(MySql, connection)
- connection.Open()
- objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
- Grid.DataSource = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
- Grid.DataBind()
- Else
- Label1.Text = "You have not specified a file."
- End If
- End Sub
- </script>
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="utf-8"?>
- <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
- <connectionStrings>
- <remove name="LocalSqlServer" />
- <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|PostOffice.mdf;User Instance=true"
- providerName="System.Data.SqlClient" />
- <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PostOffice.mdf;Integrated Security=True;User Instance=True"
- providerName="System.Data.SqlClient" />
- </connectionStrings>
- <system.web>
- <roleManager enabled="true" />
- <authentication mode="Forms" />
- </system.web>
- </configuration>
Server Error in '/MerlinLocalPostOfficeApp' Application.
--------------------------------------------------------------------------------
Format of the initialization string does not conform to specification starting at index 0.
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.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
Source Error:
Line 19: Dim fi As New FileInfo(OpenFileDialog1.FileName)
Line 20: Dim strConn As String = System.Configuration.ConfigurationManager.AppSetti ngs("connectionstring") & fi.DirectoryName
Line 21: Dim connection As New SqlConnection("strConn")
Line 22: Dim MySql As String = "SELECT * FROM " & fi.Name
Line 23: Dim objDR As SqlDataReader
Source File: c:\inetpub\wwwroot\MerlinLocalPostOfficeApp\Admini strator\Upload2.aspx Line: 21
Stack Trace:
[ArgumentException: Format of the initialization string does not conform to specification starting at index 0.]
System.Data.Common.DbConnectionOptions.GetKeyValue Pair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) +1242
System.Data.Common.DbConnectionOptions.ParseIntern al(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +128
System.Data.Common.DbConnectionOptions..ctor(Strin g connectionString, Hashtable synonyms, Boolean useOdbcRules) +102
System.Data.SqlClient.SqlConnectionString..ctor(St ring connectionString) +52
System.Data.SqlClient.SqlConnectionFactory.CreateC onnectionOptions(String connectionString, DbConnectionOptions previous) +24
System.Data.ProviderBase.DbConnectionFactory.GetCo nnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) +125
System.Data.SqlClient.SqlConnection.ConnectionStri ng_Set(String value) +56
System.Data.SqlClient.SqlConnection.set_Connection String(String value) +4
System.Data.SqlClient.SqlConnection..ctor(String connectionString) +21
ASP.administrator_upload2_aspx.UploadButton_Click( Object sender, EventArgs e) in c:\inetpub\wwwroot\MerlinLocalPostOfficeApp\Admini strator\Upload2.aspx:21
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
Please try and help in anyway, im a really newbie so try and dumb it down for me.
Thanks in advance