C#配置数据源

C#配置使用oracle数据库,可以使用VS自带的数据源配置向导。

在VS左侧数据源窗口中,点击添加数据源,弹出数据源配置向导界面。新建一个链接,如果是本地数据库,SID为FY,则直接输入服务器名(FY)和用户名、密码,测试一下连接(下图)。

Snap1

如果是远程数据库:需要在本地安装oracle客户端,并在tnsnames.ora文件中做出相应配置(可用oracle自带的Net Configuration assistance 工具)。假如配置的服务名为nnorcl,则在数据源配置向导中像本地服务一样配置即可(下图)。

Snap2

或者,将连接字符串写成以下形式(未亲自测试):

Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.169.8.71)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl)));User Id=NNMIS; Password=NNMIS;Unicode=True

=========================

连接配置:

Settings.settings文件 字符串:Provider=MSDAORA;Data Source=nnorcl;Password=NNMIS;User ID=NNMIS

app.config文件:

<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name=”WinFormsApp1.Properties.Settings.ConnRemote” connectionString=”Provider=MSDAORA;Data Source=nnorcl;Password=NNMIS;User ID=NNMIS”
providerName=”System.Data.OleDb” />
</connectionStrings>
</configuration>

This entry was posted in C#. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s