EDN Admin
Well-known member
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System.Data.SqlClient
<span style="color:Blue; Public <span style="color:Blue; Class Form1
<span style="color:Blue; Private <span style="color:Blue; Sub Button1_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button1.Click
CreateDatabase()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub CreateDatabase()
<span style="color:Blue; Dim myconnection <span style="color:Blue; As SqlConnection = <span style="color:Blue; New SqlConnection(<span style="color:#A31515; "Server=(local);" & <span style="color:#A31515; "uid=samuel;pwd=wong;database=master")
<span style="color:Blue; Dim Str <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; "CREATE DATABASE MyDatabase ON PRIMARY (NAME = NewDatabase, FILENAME = A:NewDatabase.mdf, SIZE = 2MB, MAXSIZE = 10MB, " & _
<span style="color:#A31515; "FILEGROWTH = 10%) LOG ON (NAME = MyDatabase_Log, FILENAME = A:NewDatabase.ldf, SIZE = 1MB, MAXSIZE = 5MB, FILEGROWTH = 10%)"
<span style="color:Blue; Dim myCommand <span style="color:Blue; As SqlCommand = <span style="color:Blue; New SqlCommand(Str, myconnection)
<span style="color:Blue; Try
myconnection.Open()
myCommand.ExecuteNonQuery()
MessageBox.Show(<span style="color:#A31515; "Database is created successfully", _
<span style="color:#A31515; "MyProgram", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
MessageBox.Show(ex.ToString())
<span style="color:Blue; Finally
<span style="color:Blue; If (myconnection.State = ConnectionState.Open) <span style="color:Blue; Then
myconnection.Close()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
Gives me a very very long error:
System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server
is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)<br/>
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)<br/>
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()<br/>
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity)<br/>
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)<br/>
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)<br/>
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)<br/>
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)<br/>
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)<br/>
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)<br/>
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)<br/>
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)<br/>
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)<br/>
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)<br/>
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)<br/>
at System.Data.SqlClient.SqlConnection.Open()<br/>
at ComputerTechnologyDatabase.Form1.CreateDatabase() in A:UsersSamuelAppDataLocalTemporary ProjectsComputerTechnologyDatabaseForm1.vb:line 12
Help please
Thanks in advance. <hr class="sig Striving to do my best.
View the full article
<span style="color:Blue; Imports System.Data.SqlClient
<span style="color:Blue; Public <span style="color:Blue; Class Form1
<span style="color:Blue; Private <span style="color:Blue; Sub Button1_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button1.Click
CreateDatabase()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub CreateDatabase()
<span style="color:Blue; Dim myconnection <span style="color:Blue; As SqlConnection = <span style="color:Blue; New SqlConnection(<span style="color:#A31515; "Server=(local);" & <span style="color:#A31515; "uid=samuel;pwd=wong;database=master")
<span style="color:Blue; Dim Str <span style="color:Blue; As <span style="color:Blue; String = <span style="color:#A31515; "CREATE DATABASE MyDatabase ON PRIMARY (NAME = NewDatabase, FILENAME = A:NewDatabase.mdf, SIZE = 2MB, MAXSIZE = 10MB, " & _
<span style="color:#A31515; "FILEGROWTH = 10%) LOG ON (NAME = MyDatabase_Log, FILENAME = A:NewDatabase.ldf, SIZE = 1MB, MAXSIZE = 5MB, FILEGROWTH = 10%)"
<span style="color:Blue; Dim myCommand <span style="color:Blue; As SqlCommand = <span style="color:Blue; New SqlCommand(Str, myconnection)
<span style="color:Blue; Try
myconnection.Open()
myCommand.ExecuteNonQuery()
MessageBox.Show(<span style="color:#A31515; "Database is created successfully", _
<span style="color:#A31515; "MyProgram", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
<span style="color:Blue; Catch ex <span style="color:Blue; As Exception
MessageBox.Show(ex.ToString())
<span style="color:Blue; Finally
<span style="color:Blue; If (myconnection.State = ConnectionState.Open) <span style="color:Blue; Then
myconnection.Close()
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; End <span style="color:Blue; Try
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
Gives me a very very long error:
System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server
is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)<br/>
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)<br/>
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()<br/>
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity)<br/>
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)<br/>
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)<br/>
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)<br/>
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)<br/>
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)<br/>
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)<br/>
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)<br/>
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)<br/>
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)<br/>
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)<br/>
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)<br/>
at System.Data.SqlClient.SqlConnection.Open()<br/>
at ComputerTechnologyDatabase.Form1.CreateDatabase() in A:UsersSamuelAppDataLocalTemporary ProjectsComputerTechnologyDatabaseForm1.vb:line 12
Help please

View the full article