我正在开发一个c#项目,在visual studio中注册一个新用户,并使用toad for database。符合数据库的代码是:
protected void New_User(object sender, EventArgs e)
{
OleDbConnection conn;
OleDbDataAdapter OledbAdapter = new OleDbDataAdapter();
String sql = "";
conn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
sql = "INSERT INTO USER_DETAIL VALUES('" + TextBoxUN.Text + "','" +TextBoxPass.Text+ "', '" + TextBoxEmail.Text + "','" + TextBoxmobileno.Text +"')";
try
{
conn.Open();
OledbAdapter.InsertCommand = new OleDbCommand(sql, conn);
OledbAdapter.InsertCommand.ExecuteNonQuery();
Label_success.Text = "Successfully inserted into database";
}
catch (Exception ex)
{
Label_success.Text = "Error" + ex.ToString();
}
finally
{
conn.Close();
}
}
我的web.config文件是:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="ConnString" connectionString="Provider=MSDAORA;Data Source=TRGDB;Persist Security Info=True;Password=pass;User ID=TRAINEE01" providerName="System.Data.OleDb"/>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
但我收到以下错误:
ErrorSystem.Data.OleDb.OleDbException(0x80004005):ORA-12504:TNS:侦听器未在System.Data的System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr,OleDbConnection连接)的CONNECT_DATA中获得SERVICE_NAME。 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)上的System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection,DbConnectionPoolGroup poolGroup)中的.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions选项,Object poolGroupProviderInfo,DbConnectionPool池,DbConnection owningObject) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory)位于C:\ documents和settings \中Project._Default.New_User(Object sender,EventArgs e)的System.Data.OleDb.OleDbConnection.Open()处admin \ my documents \ visual studio 2010 \ Projects \ Project \ Project \ Default.aspx.cs:第26行
答案 0 :(得分:0)
你的connectionstring应该是这样的:
数据源=(DESCRIPTION =(ADDRESS =(PROTOCOL = TCP)(HOST = MyHost)(PORT = MyPort))(CONNECT_DATA =(SERVICE_NAME = MyOracleSID))); 用户ID = myUsername;密码= myPassword;