I am trying to use a connection string from web.config file for the first time. Here is my code.
Try
Dim cmd As String = _
("SELECT [Name], BirthDate, StartDate From " & _
"Employees WHERE PayGroup='20' AND Status='A'")
Dim conn As String = _
System.Configuration. _
ConfigurationManager. _
AppSettings("myConString")
Dim myConn As New SqlConnection(conn)
Dim myCmd As New SqlDataAdapter(cmd, myConn)
Dim ds As New DataSet
myCmd.Fill(ds)
gvEmp.DataSource = ds
gvEmp.DataBind()
Catch ex As Exception
Response.Write(ex.Message & "<br>")
Finally
End Try
I am getting The ConnectionString property has not been initialized. What am I doing wrong?Show your web.config code.
<connectionStrings>
<add name="myConString" connectionString="Data Source=myServer;Initial Catalog=Employees;User ID=myUser;Password=mypass"
providerName="System.Data.SqlClient" />
</connectionStrings>
Showing posts with label dim. Show all posts
Showing posts with label dim. Show all posts
Monday, March 26, 2012
The ConnectionString property has not been initialized.
Labels:
asp,
cmd,
code,
config,
connection,
connectionstring,
dim,
file,
initialized,
net,
property,
string,
time,
web
Thursday, March 22, 2012
The files are downloaded with the html code at the end of them
I have a code that download files form a folder to the client:
The problem is that if you open the files with 'notepad' you see that the html code of the page has been incorporated to the end of the file. Something like this:
Somebody knows what can be? How can I takeout the html code?
Could you tell me what that does? I've copy the code without it and it works anyway.
Try
Response.AddHeader("Content-Disposition", "attachment;filename=" & strFileName)
Dim fs As FileStream = New FileStream("C:\text.txt", FileMode.Open, FileAccess.Read)
Dim fileData As Byte()
ReDim fileData(fs.Length)
Dim bytesRead As Long = fs.Read(fileData, 0, CInt(fs.Length))
fs.Close()
Response.BinaryWrite(fileData)
Catch es as Exception
lblAlert.text = "It was a problem transferring the file."
end try
The problem is that if you open the files with 'notepad' you see that the html code of the page has been incorporated to the end of the file. Something like this:
***************Beginning of the file***************
0000114099 00000 n
0000114243 00000 n
0000114317 00000 n
trailer<</Size 62/ID<79e93880650e9d343ab0837ab878f5cd><79e93880650e9d343ab0837ab878f5cd>]>>
startxref 173 %%EOF
<html>
<head>
<title>HLC Intranet - HLC Eroom</title>
***************rest of the html code***************
Somebody knows what can be? How can I takeout the html code?
Thanks,
BriegaHi,
I presume this is some code-behind code. Check if there is still some html code in your page (this is created automatically when you create a new webform in vs.net). Delete the html code and only leave the Page-directive.
I struggled with this issue also last year and this is what worked for me:
Response.Clear()
Response.ContentType = scan.ContentType
Response.BinaryWrite(scan.Document)
Response.End()
Grz, Kris.
It works!!!
The only part of your code that I don't understand is the
Response.BinaryWrite(scan.Document)
Could you tell me what that does? I've copy the code without it and it works anyway.
Regards,
Briega
Sorry I typed wrong!
What I don't understand is:
Response.ContentType = scan.ContentType
Briega
I'm sorry, I took a little snippet out of my code. scan is an instantiation of a custom made class which retrieves the binary data and it's accompanying contenttype (pdft, excell, word, ...)
You can search for the content types on the internet.
Grz, Kris.
Labels:
addheader,
asp,
attachmentfilename,
clienttry,
code,
content-disposition,
dim,
download,
downloaded,
files,
folder,
form,
html,
net,
response,
strfilename
Subscribe to:
Posts (Atom)