Theory
Bills को रात Survive करनी ही होगी
ShopKeeper ने अब तक जो कुछ भी बनाया है वह RAM में रहता है: app बंद कीजिए, और दिन के bills evaporate हो जाते हैं। Mehta Uncle की register book आपके DataSet पर हँसती है।
Unit 5 इसे एक असली database से fix करती है: ShopDB, एक Bills table के साथ, exactly वैसी चीज़ जो आपने BCA205 में बनाई थी।
पर database CODE की एक line लिखने से पहले, एक professional database को देखता है: कौन सी tables exist करती हैं? कौन से columns? क्या server reachable भी है? Visual Studio के पास exactly इस reconnaissance के लिए built-in tools हैं।
Theory
Tools, Formally
इस paper के लिए तीन visual database tools matter करते हैं:
- Server Explorer: databases पर IDE की window: connections add कीजिए, tables expand कीजिए, rows view और edit कीजिए, tables बनाइए, Visual Studio छोड़े बिना सब कुछ
- Query Designer: columns tick करके और tables visually join करके एक SQL query बनाइए, इसे run कीजिए, और generated SQL पढ़िए (अच्छा BCA205 revision)
- Data Sources window: एक table को form पर drag कीजिए और Visual Studio automatically एक bound grid generate करता है
ये explore और configure करते हैं; automation अभी भी code का है।
Follow along
ShopDB से Connect होना, Click by Click
- View menu, Server Explorer Panel usually left पर dock होता है, Toolbox के बगल।
- Data Connections पर Right-Click, Add Connection Data source चुनिए: server database के लिए Microsoft SQL Server, या file-based के लिए एक Microsoft Access database file (.mdb/.accdb)।
- Server और Database भरिए (या File तक Browse कीजिए) एक local SQL Server के लिए: server name . (एक dot) और database ShopDB।
- Test Connection Press कीजिए Reachability और permissions verify करता है इससे PEHLE कि आप इस पर depend करें। समस्याएँ यहाँ fix कीजिए, code में नहीं।
- नए Connection को Expand कीजिए Tables, फिर Bills: right-click, Show Table Data, और rows IDE में editable दिखते हैं।
Theory
Dialog का असली Output: एक Connection String
उस Add Connection dialog में आपने जो कुछ भी typed किया वह text की एक line तक compile होता है, connection string:
Data Source=.;Initial Catalog=ShopDB;Integrated Security=True
Data Source server को नाम देता है (एक dot का मतलब है यही machine), Initial Catalog database को, Integrated Security Windows user की तरह log in करता है। Server Explorer में connection select कीजिए और इसका Properties pane string दिखाता है, copy के लिए ready।
इसे रखिए: अगले lesson के ADO.NET objects को इनके पहले ingredient के रूप में exactly यही string चाहिए।
Quiz
Add Connection dialog में Test Connection button असल में क्या verify करता है?
- कि आपके SQL queries syntax errors से free हैं
- कि server और database दिए गए credentials से अभी reachable हैं
- कि Bills table में valid data है
- कि ADO.NET customer की machine पर installed है
Show the answer
कि server और database दिए गए credentials से अभी reachable हैं
Test Connection एक live handshake perform करता है: क्या यह machine, इन credentials के साथ, इस moment इस database को खोल सकती है? Reachability और login, इससे ज़्यादा कुछ नहीं। यह कोई tables नहीं पढ़ता (option C) और आगे आप जो queries लिखेंगे उनके बारे में कुछ नहीं जानता (option A): SQL mistakes अभी भी code में आपका wait कर रही हैं। Option D target machine को अपनी machine से confuse करता है; ADO.NET वैसे भी .NET के साथ ship होता है। जो habit यह बनाता है वही point है: कुछ भी pump करने से पहले prove कीजिए pipe काम करती है।
Think first
Tools या Code? 3 Jobs पर Rule कीजिए
तीन jobs: (1) check कीजिए कल के bills असल में Bills table तक पहुँचे या नहीं, (2) cashier जैसे ही Print click करे हर नया bill automatically save कीजिए, (3) trust करने से पहले एक SUM query try कीजिए। Tap करने से पहले हर एक को visual tools या ADO.NET code assign कीजिए।
Show the answer
(1) Tools: Server Explorer, Show Table Data: एक 10-second eyeball, कोई code deserve नहीं करता। (3) Tools: Query Designer SUM को interactively run करता है जब तक यह सही न हो जाए; THEN proven SQL code में जाता है। (2) Code: सिर्फ़ ShopKeeper के अंदर running ADO.NET ही click-time पर automatically act कर सकता है; till के साथ कोई IDE window ship नहीं होती। याद रखने लायक division: exploring, verifying और prototyping के लिए tools; जो कुछ भी APPLICATION को खुद करना है उसके लिए code, जो अगले lesson का पूरा business है।
Watch out
जहाँ Demo मरता है
Live Data को Casually Edit करना: Show Table Data typing के साथ REAL database edit करता है: आपके laptop पर ShopDB में fine, एक production shop के data में catastrophic। जानिए आप किस connection को touch कर रहे हैं।
Memory से Connection Strings Hand-Typing करना: एक misspelled Catalog और कुछ connect नहीं होता; इसके बजाय tested connection के Properties pane से copy कीजिए।
यह Assume करना कि Tools App के साथ Travel करते हैं: ये Visual Studio features हैं; deployed ShopKeeper के पास सिर्फ़ आपका code और string है।
Theory
Reconnaissance पूरा हुआ
अब आप battlefield देख सकते हैं: ShopDB reachable (tested), Bills table browsable, एक working connection string copied और wait कर रही। जो बाकी है वह SHOPKEEPER को यह सिखाना है कि run time पर वही करे जो आपने अभी हाथ से किया: connection open कीजिए, BCA205 का SQL भेजिए, results घर लाइए। वह machinery, हर एक का exactly एक job वाले 5 objects, ADO.NET object model है: अगला lesson, और इस subject की आख़िरी नई architecture।
Summary
Key takeaways
- Server Explorer Visual Studio के अंदर databases से connect होता है और उन्हें browse करता है: tables, data, यहाँ तक कि table creation भी।
- Add Connection: provider चुनिए (SQL Server या Access file), server और database नाम दीजिए, फिर हमेशा Test Connection कीजिए।
- Query Designer visually SQL बनाता और test-run करता है; Data Sources tables को bound grids में drag करता है।
- Dialog का असली product connection string है: Data Source, Initial Catalog, security settings।
- Tools explore, verify और prototype करते हैं; ADO.NET code automate करता है: दोनों, इसी order में।
- Show Table Data असली database edit करता है: जिस connection पर आप हैं उसका respect कीजिए।
- Memory hook: pump करने से पहले pipe test कीजिए।