Connections Present levels GoalsServicesLRE Connections Present levels GoalsServicesLRE.
Neal Stublen [email protected]. Open/Close Connections ADO.NET uses “connection pooling” to...
-
Upload
myrtle-wilkins -
Category
Documents
-
view
215 -
download
0
Transcript of Neal Stublen [email protected]. Open/Close Connections ADO.NET uses “connection pooling” to...
![Page 2: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/2.jpg)
Open/Close Connections
ADO.NET uses “connection pooling” to optimize opening and closing connections to the database
cxn.Open() and cxn.Close() are using connections from the connection pool that share the same connection string
ADO.NET manages the actual connection to the database
http://msdn.microsoft.com/en-us/library/8xx3tyca(v=vs.110).aspx
![Page 3: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/3.jpg)
Think of it like this…class SqlConnectionPool{ public SqlConnection Open(string cxnStr) { if (mPool.Contains(cxnString)) { return mPool[cxnString]; } // Create a new connection ... }}
![Page 4: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/4.jpg)
And…class SqlConnectionPool{ public void CheckIdle() { foreach (cxn in mPool) { if (cxn.IsIdle()) { cxn.ReallyClose(); mPool.Remove(cxn); } } }}
![Page 5: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/5.jpg)
DataSets in Class Libraries Create a DataSet in the class libraries Select “Referenced DataSets” when
adding a DataSet control to a form Add a BindingSource Add form controls and bind them to the
BindingSource
![Page 6: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/6.jpg)
MENUS, TOOL BARS, AND STATUS BARS
![Page 7: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/7.jpg)
Designer Walkthrough
![Page 8: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/8.jpg)
Summary
MenuStrip w/ defaults ToolStrip w/ defaults StatusStrip View Menu Toggles PerformClick() ToolStripContainer w/ docking ContextMenuStrip SplitContainer ErrorProvider
![Page 9: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/9.jpg)
FILES AND DATA STREAMS
![Page 10: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/10.jpg)
File System Static Classes System.IO namespace Directory
CreateDirectory, Exists, Delete File
Exists, Delete, Copy, Move Path
Combine, GetDirectoryName, GetFileName, GetExtension, GetTempFileName
DirectorySeparatorChar, VolumeSeparatorChar
![Page 11: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/11.jpg)
File System Instance Classes
DirectoryInfoEnumeratorDirectories(), EnumerateFiles()
FileInfoName, Length, Open(), OpenText()
![Page 12: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/12.jpg)
File System Exceptions
FileNotFoundException DirectoryNotFoundException EndOfStreamException IOException
![Page 13: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/13.jpg)
Stream Classes
FileStream StreamReader StreamWriter BinaryReader BinaryWriter
![Page 14: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/14.jpg)
Code Practice
Browse for a text file Place the filename in a TextBox Read each line from the file and insert
into a ListView Use two columns in the ListView
Line numberContent
![Page 15: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/15.jpg)
Review
OpenFileDialog ImageList ListView, DetailsView
![Page 16: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/16.jpg)
XML FILES
![Page 17: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/17.jpg)
What’s XML?
Structured data file Tags identify each data element Tags can have attributes and child tags
<Books> <Book Code=“BK0001”> <Name>Having Fun in Kansas City</Name> <Price>19.95</Price> </Book> </Books>
![Page 18: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/18.jpg)
XML Tags
Elements are identified by start tags, <tag_name>, and end tags, </tag_name>
Content can be placed between tags in the form of text or additional elements
Elements can be described using a single tag, <tag_name />
Comments are tags in the form,
<!-– my comment -->
![Page 19: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/19.jpg)
Tag Attributes
In addition to content, each tag can also contain zero, one, or more attributes instead of child elements:
<Book ISBN=“978-1-890774-59-2”></Book>
<Book> <ISBN>978-1-890774-59-2</ISBN></Book>
![Page 20: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/20.jpg)
Working with XML Files
Any text editor can be used to create XML files
Visual Studio helps create and edit XML filesCreates XML declarationColor coded tagsAutomatic indentation and closing tagsExpanding and collapsing tags
![Page 21: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/21.jpg)
XmlReader/XmlWriter
System.XML is the namespace that contains XML classes
Useful for exporting and importing data in a common format
![Page 22: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/22.jpg)
Writing XML FilesXmlWriter w = XmlWriter.Create(path, settings);w.WriteStartDocument();
// A start tagw.WriteStartElement(root_name);// A nested start tagw.WriteStartElement(parent_name);// An attribute on the parent_name tagw.WriteAttributeString(name, value);// A complete elementw.WriteElementString(child_name, value);// End tags for parent_name and rootw.WriteEndElement();w.WriteEndElement();
w.Close();
![Page 23: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/23.jpg)
Using XMLWriterSettings
Define indentation
XmlWriterSettings settings = new XmlWriterSettings();settings.Indent = true;settings.IndentChars = " ";
![Page 24: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/24.jpg)
Code Practice
Create a new project called CustomerExport
Export the rows from the Customers table to Customers.xml
Consider how you would use SqlConnection, SqlCommand, and SqlReader
Save the XML file on the Desktop as…
![Page 25: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/25.jpg)
XML Format<Customers> <Customer id="157"> <Name>Abeyatunge, Derek</Name> <Address>1414 S. Dairy Ashford</Address> <City>North Chili</City> <State>NY</State> <ZipCode>14514 </ZipCode> </Customer> ...</Customers>
![Page 26: Neal Stublen nstublen@jccc.edu. Open/Close Connections ADO.NET uses “connection pooling” to optimize opening and closing connections to the database.](https://reader031.fdocuments.in/reader031/viewer/2022032313/56649e435503460f94b3695c/html5/thumbnails/26.jpg)
Review
MemoryStream XmlWriter SqlDataReader “inspection” System.Environment.GetFolderPath FileStream Debugging visualizers