using
System.Data.Sqlcolint
using
System.Xml
悬赏分:20
-
提问时间2007-11-6
16:34
我的问题:
1。连接数据库方式是个类库(做成dll文件)
2。连接数据库的登录名密码等字符串是从config.xml中读取
3。是从类库中读取还是从别的地方读取config.xml?因为在类库中有个连接数据库的语句。
4。如果连接数据库的密码错误,会自动提示连接错误,然后d出个小窗口,修改config.xml中的数据库密码等,然后保存。这个步骤在哪里写?
===================================================================================================================
我的部分代码:
1。连接数据库的类库:
Imports
System.data.sqlclient
Public
Class
DB
'sCon为连接字符串
Private
sCon
As
String
=
"User
ID=saInitial
Catalog=dbnameData
Source=(local)
"
Public
Function
GetDataTable(ByVal
strSql
As
String)
As
DataTable
Dim
myDt
As
New
DataTable
Dim
sqlConn
As
SqlConnection
=
New
SqlConnection(sCon)
Dim
myCmd
As
SqlCommand
=
New
SqlCommand(strSql,
sqlConn)
Dim
myDa
As
New
SqlDataAdapter(strSql,
sqlConn)
Try
myDa.Fill(myDt)
Catch
er
As
Exception
Finally
sqlConn.Close()
End
Try
Return
myDt
End
Function
End
Class
public
Void
ReaderXML(string
URL)//URL是XML文件的路径
{
DataSet
ds
=
new
DataSet()
ds.ReaderXml("URL")
//下面就是把这个数据集存到数据库里面
}
spring链接配置即可。
一、<dependencyManagement>
<dependencies>
<!-- 使用spring的BOM管理依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.2.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
二、<!-- spring配置开始 --><dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- spring配置结束 -->
三、在web工程的src/main/resources/META-INF目录下添加dispatcher.xml文件,并添加如下配置:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
AppSettings(用在vs2003,05也可以用)<add key="connectionfstringname" value="data source=服务器名或ipinitial catalog=数据库名user id=用户;password=密码"></add>//可以省略(user id=用户;password=密码)ConnectionStrings<connectionstrings><addname="connectionstringname" connectionstring="data source=服务器名;initial
catalog=数据库名;user id=用户;password=密码"
providername="system.data.sqlclient"/></connectiionstring>直接连接数据库文件(1)在webconfig里配置
<connectionstrings><add name="connectionstringname"
connectionstring="data source=./sqlexpressintegrated
security=sspiAttachDBFilename=|DataDirectory|database.mdf
"providerName="system.data.sqlclient"</connectionsttrings>(2).直接引用SqlConnection
conn = new SqlConnection(Data Source=./SQLExpressIntegrated
Security=SSPIAttachDBFilename=|DataDirectory|database.mdfUser
Instance=true)DataDirectory默认是AppData文件夹,你把mdf文件放到里面,改一下文件名(database.mdf)和连接字符串的一样就行了
WinForm连接字符串app.config(基于.net2.0)首先在项目的属性文件夹下使用 Settings.settings 配置连接字符串,我这里配置了一个 Access数据库
连接保存后VS2005自动生成 app.config文件(修改 Settings.settings配置此文件会自动更新),内容如下:
<?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> </configSections> <connectionStrings>
<add name="frmSignIn.Properties.Settings.DBConnString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0DataSource=F:/kaifa/frmSignIn/appData/dbqx.mdbPersist
SecurityInfo=TrueJet OLEDB:Database Password=123"providerName="System.Data.OleDb" /> </connectionStrings></configuration>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)