WPF 一个数据库连接测试的实现

前端之家收集整理的这篇文章主要介绍了WPF 一个数据库连接测试的实现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

要实现的功能效果图如下:因为我们要测试数据是从输入框获得的,所以,我们的连接字符串不是写死在应用程序中的。下面我就详细介绍一下。

 

dpn1rpY3bYsfb86NZFb3a3u1vn1d/qI+T7DAQCgelpa2947P7e3u39vd//eWLI9lpxbvPC3z/1DW9uPpGZs96ECwI6EOLavZ4BpBo4BQJAQxzrig/t6Bvb19O/t7gfHACBIWlrbzs7Md/YOdsQHO3oG9vUMzC3mwDEACAziWFdiqLN3qCM+2BEfmAfHACBAWlrbzs0uRPuGuxLDRLP5JXAMAIKDOBbrG2GazS9dBMcAIDBaWtvOzy3EkqNMswVwDAACpKW17fzcYnf/aCw5GkuORPtGFi6AYwAQHMSxnoH93f37u5OjseTo4oVL4BgABIbr2AGmGTgGAEFCHIsPHiCa9fTvX8yBYwAQHC2tbTNzi/HBg/HBA/GBAz0D+xdz74NjABAYLa1tM/OLvYMHe13NwDEACBLq2NDB3iGq2RI4BgAB0tLaNjO/xBzrHTy4dBEcA4DgII4lhp5PDD1PTAPHACBIeMeIZuAYAASJ4tjz4BgABInkWGLo+QsXfw2OAUBggGMAEC7gGACECzgGAOECjgFAuIBjABAuwTlmWymEHce2Uma+6P4HZyJmviitZuaLjoMzEUNBWtdxHNsyDQNh+cMwYptYtveHt0xYU91e2D23mfC3ux1GRorusZjn32eL5eUikYzv5wNNQJBxzLZSZh5bKRMhk/RPVyh5JeKY1PWZj4ozqkEYGURokzjG7Yosc/fpsyt3fW9l8sq2TM4sttdi3iSisBeOoJ5TzJvkNXvB3sUIHGtuuH8TXJtjtpWSXchbYqxCCLG/TVN342eOcQ5oo1AJxzBy4xhG5HP4sEYWsgUVxTFhY08YyTH/mwI41twE5hgBZ4g8dNTodlNuyOgfx7ydIANZlk+nNd0o4f1NHPP0oCGUj0iGadlkDUE4EXcTYXhJPylFhqQpbmvXK0UhFssAw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zlD6QDAOkB0iGllMvl6enpra2tt2/f/jtN8HAYsrEbDuGrQCAdAEgPkA4ppVwuFwqF+fn57e3t/TTBw2F4eDiEr8L7atCXNgCg7wxGOnS7xzHK8fFxlxevstvpdjvdLqRDVLivZmZmpqenLwNf4Kvw4DMIQBroo3TYc3jnwBvs7u6+fPU6SvnPi52XL3Zebr/Yeb6983x7Z3Nre2Pz+cbm82cbW+vPNtefba6urrbb7TIAAAAA+k/vpUPUXQAAAAAwQkA6AAAAACACkA4AAAAAiACkAwAAAAAiAOkAAAAAgAhAOgAAAAAgApAOAAAAAIgApAMAAAAAIgDpAAAAAIAIQDoAAAAAIAKQDgAAAACIAKQDAAAAACIA6QAAAACACEA6AAAAACACkA4AAAAAiACkAwAAAAAiAOkAAAAAgAhAOgAAAAAgApAOAAAAAIgApAMAAAAAIgDpAAAAAIAIQDoAAAAAIAJkrP9/7iK+pW1p00UAAAAASUVORK5CYII=" alt="">

新建一个连接字符串名称,类型为 string,重点重点 范围一定要设置为 用户,这样的话我们才可以重写base.在继承的基础上覆盖上次的连接字符串。 如果我们不设置为用户而设置为应用程序获的话,将会不可改变连接字符串。

在EF框架中,我们每new一个 DataContext便会有一个数据库表的映射。它的逻辑是,我们new的时候(此例子 datacontext是 )会执行

( Console.WriteLine(</span><span style="color: #0000ff;"&gt;global</span><span style="color: #000000;"&gt;::DataModal.Properties.Settings.Default.StockManageSystemConnectionString); OnCreated(); } </span><span style="color: #0000ff;"&gt;public</span> StockManageDataContext(<span style="color: #0000ff;"&gt;string</span><span style="color: #000000;"&gt; connection) : </span><span style="color: #0000ff;"&gt;base</span><span style="color: #000000;"&gt;(connection,mappingSource) { OnCreated(); } </span><span style="color: #0000ff;"&gt;public</span><span style="color: #000000;"&gt; StockManageDataContext(System.Data.IDbConnection connection) : </span><span style="color: #0000ff;"&gt;base</span><span style="color: #000000;"&gt;(connection,mappingSource) { OnCreated(); } </span><span style="color: #0000ff;"&gt;public</span> StockManageDataContext(<span style="color: #0000ff;"&gt;string</span><span style="color: #000000;"&gt; connection,System.Data.Linq.Mapping.MappingSource mappingSource) : </span><span style="color: #0000ff;"&gt;base</span><span style="color: #000000;"&gt;(connection,mappingSource) { OnCreated(); } </span><span style="color: #0000ff;"&gt;public</span><span style="color: #000000;"&gt; StockManageDataContext(System.Data.IDbConnection connection,mappingSource) { OnCreated(); }</span></pre>
这个代码中就是可以覆盖的连接字符串,我们只需要更改他就行。

代码来了来了
</span><span style="color: #008000;"&gt;//</span><span style="color: #008000;"&gt;获得连接字符串</span> <span style="color: #0000ff;"&gt;string</span> ConnectionString = <span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;Data Source=</span><span style="color: #800000;"&gt;"</span> + Server.Text + <span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;;Initial Catalog=</span><span style="color: #800000;"&gt;"</span> + <a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a>name.Text + <span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;;Persist Security Info=True;User ID=</span><span style="color: #800000;"&gt;"</span> + Account.Text + <span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;;Password=</span><span style="color: #800000;"&gt;"</span> +<span style="color: #000000;"&gt; Pass.Text; <a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a>Connection _<a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a>Connection </span>= <span style="color: #0000ff;"&gt;new</span><span style="color: #000000;"&gt; <a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a>Connection(ConnectionString); </span><span style="color: #0000ff;"&gt;try</span><span style="color: #000000;"&gt; { _<a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a>Connection.Open(); <a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a>Command <a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a>cmd </span>=<span style="color: #000000;"&gt; _<a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a>Connection.CreateCommand(); <a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a>cmd.CommandText </span>= <span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;select top 10 * from ProductInfo;</span><span style="color: #800000;"&gt;"</span><span style="color: #000000;"&gt;; </span><span style="color: #008000;"&gt;//</span><span style="color: #008000;"&gt;如果可以连接成功则 保存<a href="https://www.jb51.cc/tag/shujuku/" target="_blank" class="keywords">数据库</a>连接字符串 </span> DataModal.Properties.Settings.Default.StockManageSystemConnectionString =<span style="color: #000000;"&gt; ConnectionString; DataModal.Properties.Settings.Default.Save();</span><span style="color: #008000;"&gt;//</span><span style="color: #008000;"&gt;使用Save<a href="https://www.jb51.cc/tag/fangfa/" target="_blank" class="keywords">方法</a>保存更改 n</span> Message<a href="https://www.jb51.cc/tag/Box/" target="_blank" class="keywords">Box</a>.Show(<span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;测试连接正常</span><span style="color: #800000;"&gt;"</span>,<span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;恭喜</span><span style="color: #800000;"&gt;"</span><span style="color: #000000;"&gt;); </span><span style="color: #0000ff;"&gt;return</span> <span style="color: #0000ff;"&gt;true</span><span style="color: #000000;"&gt;; } </span><span style="color: #0000ff;"&gt;catch</span><span style="color: #000000;"&gt; (Exception ex) { Message<a href="https://www.jb51.cc/tag/Box/" target="_blank" class="keywords">Box</a>.Show(</span><span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;不能连接<a href="https://www.jb51.cc/tag/shujuku/" target="_blank" class="keywords">数据库</a>,请重新设置</span><span style="color: #800000;"&gt;"</span>,<span style="color: #800000;"&gt;"</span><span style="color: #800000;"&gt;警告</span><span style="color: #800000;"&gt;"</span><span style="color: #000000;"&gt;); </span><span style="color: #0000ff;"&gt;return</span> <span style="color: #0000ff;"&gt;false</span><span style="color: #000000;"&gt;; } </span><span style="color: #0000ff;"&gt;finally</span><span style="color: #000000;"&gt; { _<a href="https://www.jb51.cc/tag/sql/" target="_blank" class="keywords">sql</a>Connection.Close(); } }</span></pre>

这样就可以进行测试了,在每次登陆之前都要验证一遍。

 

还有一个比较人性化的问题,就是用户希望在每次登陆之前都有几个数据库连接默认的值,毕竟大家不愿意去动手输入那么多数据,但是又不可以直接写死在输入框(这样太low),所以,既然之前我们可以给连接字符串赋值,我们也可以获取上次的连接字符串,拆分,然后在窗体初始化时默认加载到窗体输入框嘛。

代码:(根据键值对获得,)

connect =<,> dictionary = connect.Split( [] { },StringSplitOptions.RemoveEmptyEntries).ToDictionary(x => x.Split()[],x => x.Split()[<> test = List<> ( i = ; i < test.Count; i++= test[sqlname.Text = test[= test[= test[

 

 



原文链接:https://www.f2er.com/aspnet/238740.html

猜你在找的asp.Net相关文章