Database Operation
来源:互联网 发布:超市软件 编辑:程序博客网 时间:2024/04/26 04:22
[Simple Connection With Local & Windows Authenticationi]
String strConn = "Server = (local);" + "integrated security = SSPI;" + "database = factory"; SqlConnection conn = new SqlConnection(strConn); try { conn.Open(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } finally { conn.Close(); }
[Connetion String with UserId and Password]
String strConn = "Persist Security Info=False;" + "User ID=Rich;" + "Password=1984;" + "Initial Catalog=factory;";
[Connetion String with Database Server's IP]
String strConn = "Server =192.168.1.101;"+ "Persist Security Info=False;" + "User ID=Rich;" + "Password=1984;" + "Initial Catalog=factory;";
[Create Connection Using Web.config]
// in Web.config
/* <configuration>
<appSettings/>
<connectionStrings>
<add name ="Factory" providerName="System.Data.SqlClient" connectionString="Server = (local);integrated security =SSPI;database =factory"/>
</connectionStrings>*/
// encrypt at console >aspnet_regiis -pef "connectionStrings" F:/MyStudy/Dragon////////////////////////////////////////////////////////// // in .CS file ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["Factory"]; DbProviderFactory pf = DbProviderFactories.GetFactory(settings.ProviderName); DbConnection conn = pf.CreateConnection(); conn.ConnectionString = settings.ConnectionString;//////////////////////////////////////////////////////////////////////////////////////////////////////// ConnectionStringSettings stringSettings = ConfigurationManager.ConnectionStrings["Factory"];// SqlConnection conn = new SqlConnection(stringSettings.ConnectionString);//////////////////////////////////////////////////////////////////////////////////////////////////////
[Use Transaction Code]
_conn.Open();SqlTransaction tran = _conn.BeginTransaction(); String strSql = "UPDATE [USER] SET password =/'xsd/' WHERE username = /'test/';"; SqlCommand cmd = new SqlCommand(strSql,_conn); cmd.Transaction = tran; int result = cmd.ExecuteNonQuery(); tran.Rollback(); //tran.Commit();
[Use Store Procedure code]
SqlCommand cmd = new SqlCommand("ASimpleProcedure", _conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@username", SqlDbType.VarChar, 20)); cmd.Parameters.Add(new SqlParameter("@age", SqlDbType.Int, 20)); cmd.Parameters["@username"].Value = "test"; cmd.Parameters["@age"].Value = 24; try { _conn.Open(); cmd.UpdatedRowSource = UpdateRowSource.OutputParameters; cmd.ExecuteNonQuery(); }
- Database Operation
- operation database in the transaction object
- An simple operation in Database Vault.
- sqlite ORM(automatic database operation)
- ORA-12720: operation requires database is in EXCLUSIVE mode
- ORA-12719: operation requires database is in RESTRICTED mode
- 120.For which database operation would you need the database to be in the MOUNT state?
- operation
- sql中:The database could not be exclusively locked to perform the operation. 错误处理
- Error: ORA-16501: the Data Guard broker operation failed ORA-16625: cannot reach database
- Error: the database could not be exclusively locked to perform the operation[解决办法]
- ORA-15061 reported while doing a file operation with 11.1 or 11.2 ASM after PSU applied in database
- 修改数据库Collocation时出现的The database could not be exclusively locked to perform the operation(SQL Server
- The database could not be exclusively locked to perform the operation(SQL Server 5030错误解决办法)
- 编辑排序规则The database could not be exclusively locked to perform the operation(SQL Server 5030错误解决办法)
- DataBase
- Database
- database
- 特殊字符在FTP,SQLPLUS中的应用
- TraceRoute小贴
- c++ 前向声明
- Java调用.dll库文件中定义的方法
- JBoss数据源配置文档
- Database Operation
- 在Sqlserver分组中加入行号
- javascript关闭firefox窗口,无警告提示的
- Amoeba 0.17 版本发布,增加了几个特性
- RAS 函数
- ICMP小贴
- Hibernate中引用View的解决方案_来自一网友
- 正则表达式30分钟入门教程(第二版)
- 互联网产品设计文档类型:BRD、MRD、PRD和FSD