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 '/MerlinLocalPost OfficeApp' 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.Argument Exception: Format of the initialization string does not conform to specification starting at index 0.
Source Error:
Line 19: Dim fi As New FileInfo(OpenFi leDialog1.FileN ame)
Line 20: Dim strConn As String = System.Configur ation.Configura tionManager.App Settings("conne ctionstring") & fi.DirectoryNam e
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\wwwr oot\MerlinLocal PostOfficeApp\A dministrator\Up load2.aspx Line: 21
Stack Trace:
[ArgumentExcepti on: Format of the initialization string does not conform to specification starting at index 0.]
System.Data.Com mon.DbConnectio nOptions.GetKey ValuePair(Strin g connectionStrin g, Int32 currentPosition , StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) +1242
System.Data.Com mon.DbConnectio nOptions.ParseI nternal(Hashtab le parsetable, String connectionStrin g, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +128
System.Data.Com mon.DbConnectio nOptions..ctor( String connectionStrin g, Hashtable synonyms, Boolean useOdbcRules) +102
System.Data.Sql Client.SqlConne ctionString..ct or(String connectionStrin g) +52
System.Data.Sql Client.SqlConne ctionFactory.Cr eateConnectionO ptions(String connectionStrin g, DbConnectionOpt ions previous) +24
System.Data.Pro viderBase.DbCon nectionFactory. GetConnectionPo olGroup(String connectionStrin g, DbConnectionPoo lGroupOptions poolOptions, DbConnectionOpt ions& userConnectionO ptions) +125
System.Data.Sql Client.SqlConne ction.Connectio nString_Set(Str ing value) +56
System.Data.Sql Client.SqlConne ction.set_Conne ctionString(Str ing value) +4
System.Data.Sql Client.SqlConne ction..ctor(Str ing connectionStrin g) +21
ASP.administrat or_upload2_aspx .UploadButton_C lick(Object sender, EventArgs e) in c:\inetpub\wwwr oot\MerlinLocal PostOfficeApp\A dministrator\Up load2.aspx:21
System.Web.UI.W ebControls.Butt on.OnClick(Even tArgs e) +105
System.Web.UI.W ebControls.Butt on.RaisePostBac kEvent(String eventArgument) +107
System.Web.UI.W ebControls.Butt on.System.Web.U I.IPostBackEven tHandler.RaiseP ostBackEvent(St ring eventArgument) +7
System.Web.UI.P age.RaisePostBa ckEvent(IPostBa ckEventHandler sourceControl, String eventArgument) +11
System.Web.UI.P age.RaisePostBa ckEvent(NameVal ueCollection postData) +33
System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +5102
Please try and help in anyway, im a really newbie so try and dumb it down for me.
Thanks in advance