SQL Server 2008 Instance connection issue - sql

My problem is the following:
I installes SQL Server 2008 R2 on my Windows Server 2008. I tried it by using default instance name (MSSQLSERVER) and named instance. The Installation was successful without an error. The problem is now:
When I try to connect to my SQL Server with the Management Studio it can't connect to this instance when I write "SERVER1\MSSQLSERVER" as serveraddress. When I write "SERVER1" only in the serveradress field it works.
Note: I always try to connect as SA. The password is right. Dont know if that matters...
But I have to be able to connect to "SERVER1\MSSQLSERVER" because I always get errors when I want to connect to a server without instance by C#.
Can someone tell me where I am mistaking?
EDIT:
The C# code looks like this:
sqlConnection = "data source=(local);persist security info=True;User ID=sa;Password=12345;initial catalog=BBKat"
SqlConnection sqlCon = new SqlConnection( sqlConnection );
SqlCommand sqlCmd = new SqlCommand( sqlCmdString, sqlCon );

I think you are not mistaken at all. You do not write the default instance name while connecting. You can create aliases though as mentioned above.

Try with a single (local) in the server name. and the same in C# web config connectionString as Data Source=(local);Initial Catalog=YOUR_DB;Integrated Security=True
EDIT
Change the connection string as:
data source=(local);Integrated Security=False;User ID=sa;Password=12345;initial catalog=BBKat

Related

Connect to Oracle 10g

I finished my project with MSSQL 2008r2 database And vb.net
My company have oracel ERP System (oracle10g+ora6i form)
And I need to move same data from my project. To the company's system
I use
System.Data.SqlClient
library
i need way to connect my Project to erp db
You can use the connection string
string oracle_conn= "Data Source=(DESCRIPTION =(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST = server_Ip_oracle)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = database_name)));User ID=User/Schema;Password=password;Unicode=True";
and then use the code like
using (OracleConnection objConn = new OracleConnection(oracle_conn))
{
Your code here
}

Trouble establishing connection to Local SQL database

Simply trying to find out the correct syntax for my connection string. Before anyone asks, yes I did look at other SO answers, and no they did not work for me. Here a couple of attempts I made from looking at other SO questions like the one I am asking
Server=(local);Database=SalesOrdersExample;Integrated Security= true
Data Source=(local);Database=SalesOrdersExample;Integrated Security=SSPI
Server=.\\SQLEXPRESS;Database=SalesOrdersExampleDataSet;Integrated Security=true
None of them worked (I have a Console.WriteLine("test"); thrown in there and it works up until I try conn.Open() (opening the connection to database) so I'm assuming that it must be my connection string since nothing gets written after conn.Open())
Console.WriteLine("test"); // works
SqlConnection conn = new SqlConnection("Server=.\\SQLEXPRESS;Database=SalesOrdersExampleDataSet;Integrated Security=true");
Console.WriteLine("test"); // works
conn.Open();
Console.WriteLine("test"); // does not work
So some information about the database is that it's local under my 'Data Connections' in my Server Explorer. I also have the .xsd file in my project so I have linked the Data Set to the current project I am on. Here is a picture representation to confirm that I have both the Data Connection and the Data Set.
EDIT: SO does not allow me to post pictures until I have 10 rep so here is direct link to picture:
DB Screenshot
Any help is appreciated thank you.
Visual Studio comes with LocalDB database, which is not exactly SQL Server Express database.
Try something like this:
Server=(localdb)\v11.0;Integrated Security=true;
or
Data Source=(LocalDB)\v11.0; AttachDbFileName=|DataDirectory|\DatabaseFileName.mdf; InitialCatalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True
If using in c# code, you can use # to avoid problems with backslash characters:
SqlConnection conn =
new SqlConnection(#"Server=(localdb)\v11.0;Integrated Security=true;");

Can I access an encrypted SQL Server Compact database in Excel VBA?

I want to access an encrypted SQL Server Compact Edition database via VBA. I can access the database fine when it is not encrypted, but the code breaks when I try to use a password:
pConn.ConnectionString = "PROVIDER=Microsoft.SQLSERVER.CE.OLEDB.3.5;Password=[my_password];Data Source=" & SdfPath
I've been following the connection string example provided here for SQL Server Compact with a password:
Encryption enabled
Use this connection string to enable encryption on the database.
Data Source=MyData.sdf;Encrypt Database=True;Password=myPassword;
File Mode=shared read;Persist Security Info=False;
The Encrypt Database="True" pair is really not necessary as the presence of the Password-parameter itself turns on encryption for the connection.
But why doesn't this work in Excel VBA 2010?
Apparently, the connection string example in the site I was using is incorrect. I found the correct connection string example from Microsoft:
Using Microsoft ActiveX® Data Objects for Windows CE (ADOCE), Microsoft ActiveX Data Objects Extensions for Data Definition Language (DDL) and Security (ADOXCE), or the Replication object
To create a password-protected database using the either the ADOCE or ADOXCE Catalog object, or the AddSubscription method of the SQL Server CE Replication ActiveX object, you must specify the provider-specific SSCE:Database Password connection property in the connection string. For example:
"Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0; data source=\NorthWind.sdf; SSCE:Database Password=[myPassword]"
And so now my code is:
pConn.ConnectionString = "PROVIDER=Microsoft.SQLSERVER.CE.OLEDB.3.5;SSCE:Database Password=[my_password];Data Source=" & SdfPath
This worked perfectly for me.
If you have SQL Server Compact 4.0 installed and use "Microsoft.SQLSERVER.CE.OLEDB.2.0" or "Microsoft.SQLSERVER.CE.OLEDB.3.5" as provider in connection string, you will get an error mentioning provider not found. Change connection string to reflect to "Microsoft.SQLSERVER.CE.OLEDB.4.0".

wcf service can't update a dbf file - "read only" error

I have a wcf 4 service that is trying to add a record to a visual fox pro dbf file on the same server. When it tries to do the insert I get "Cannot update the cursor USER, since it is read-only."
I assume that this is a permissions problem. What do I have to do to give permission to the wcf service to update my dbf file?
This works on my develpment machine.
Here is some of the code:
OleDbConnection oConn = new OleDbConnection("provider=vfpoledb;Data Source="\\data\\tt.dbc");
oConn.Open();
OleDbCommand oCommand = new OleDbCommand();
oCommand.Connection = oConn;
oCommand.CommandText = "SET NULL OFF\r\nSET DELETED ON";
oCommand.ExecuteNonQuery();
OleDbCommand mycmd = new OleDbCommand("insert into user (lastname,firstname) values ('Doe','John')", oConn);
mycmd.CommandType = CommandType.Text;
lnRet = mycmd.ExecuteNonQuery();
It's not a permissions problem - that would generate an access denied error.
Two things to check:
Is the file marked as read-only?
Is the file being used by any other process?
I think #2 is more likely - I haven't done FoxPro, but I've done a lot of dBase with Clipper, and at least under dBase the file has to be opened exclusively (i.e., not shared) to do inserts/updates/deletions.
You need to verify that the credentials that are used to run the WCF service have Read/Write access to the data UNC path.

Failure to create a SQL Azure login with SMO

The following piece of code works with regular SQL and SMO. I'm trying to get it to work with SQL Azure. According to this MSDN article, a limited subset of functionality that I need (database and login creation) should be supported. All the business checking whether an object exists will also fail: server.Logins[loginName] != null or server.Databases.Contains(dbName). I can create a database if I dont check whether it exists or not, but i cant create a login. Anyone else ran into the same problem?
string connectionString =
"Server=tcp:XXXXXX.database.windows.net;Database=MyDatabase;User ID=XXXXXXX;Password=XXXXXX;Trusted_Connection=False;Encrypt=True;TrustServerCertificate=true;"
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
ServerConnection serverConnection = new ServerConnection(connection);
Server server = new Server(serverConnection);
Login login = new Login(server, "NewLogin");
login.LoginType = LoginType.SqlLogin;
login.Create("NewStrongPwd123***");
}
Create failed for Login 'NewLogin'.
at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImpl()
at Microsoft.SqlServer.Management.Smo.Login.Create(SecureString password)
at Microsoft.SqlServer.Management.Smo.Login.Create(String password)
Proposed answers to this question were identified on the MSDN Forum including a working approach. Please take a look at: http://social.msdn.microsoft.com/Forums/en-US/ssdsgetstarted/thread/26e42082-e649-4cde-916d-c1da2275e377