连接到Web服务器上的数据库 [英] connecting to database on web server

查看:142
本文介绍了连接到Web服务器上的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我正在从事C#项目,并且在我的项目中使用Microsoft Access数据库和
此连接字符串:

hi every body
I''m working on c# project and I''m using microsoft access database in my project with
this connection string:

private OleDbConnection newconnection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source = c:\telephone.accdb;Jet OLEDB:Database Password=0000;");


但是现在我想将我的数据库上传到Web服务器,并使我的项目从任何具有Internet连接的计算机上与它连接.....


but now I want to upload my database to a web server and make my project connect with it from any computer has an internet connection .....
can any body help me how to do that ???

推荐答案

您不能使用Access数据库执行所需的操作.

Access(Jet)是基于文件的桌面数据库引擎.您必须能够使用UNC路径或映射的驱动器来访问数据库文件,并且必须能够写入该文件夹.将这种文件共享暴露给Internet绝对是疯狂的.您将不会有很长时间的数据库文件.

将数据库公开到Internet的一种更安全的方法是将其隐藏在Web服务之后.该Web服务处理您的应用程序的所有数据库访问.
You cannot use an Access database to do what you want.

Access (Jet) is a desktop, file-based database engine. You have to be able to use UNC paths or mapped drives to get to the database file and you must be able to write to that folder. Exposing this kind of file share to the Internet is utterly insane. You won''t have a database file for very long.

A much safer way to expose the database to the Internet is to hide it behind a web service. The web service handles all database access for your application.


您好,

尝试以下示例:
Web.Config 文件中添加:
Hi,

Try this Example:
In your Web.Config file add:
   <connectionstrings>	
    <add name="ORAConnection" connectionstring="Provider=MSDAORA;Data Source=YourServerName;User ID=YourDbfSchemaName;Password=YourPassword" />
    <-- Some code here..-->
</connectionstrings>



在示例后面的代码中:



In your code behind Example:

   public string GetPassportNo(string cardNo)
{
    string retVal = string.Empty;
    string strConn = ConfigurationManager.ConnectionStrings["ORAConnection"].ConnectionString.ToString();
    StringBuilder sb = new StringBuilder();
    sb.Append("select *  from " + oracleSchema + ".Employee where Card_no = ''" + cardNo + "'' ");
    OleDbConnection oConnection = new OleDbConnection(strConn);
    oConnection.Open();
    using (ocmd = new OleDbCommand(sb.ToString().Trim(), oConnection))
    {
       ocmd.CommandType = CommandType.Text;
       using (OleDbDataReader dr = ocmd.ExecuteReader(CommandBehavior.CloseConnection))
       {
          if (dr.Read())
          {
              retVal = Tools.XPTools.Conversion.IifStr(dr["Passport_No"]);
          }
       }
    }
    return retVal;
}



希望这可以帮助...

请记住,如果有帮助,请将其标记为答案;如果没有帮助,则将其取消标记.

问候,

代数



Hope this could help...

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Regards,

Algem


这篇关于连接到Web服务器上的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆